This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.0.1
We were not able to find the expected elm-package.json file at this tag.
Tag 1.0.2
Committed At 2019-10-26 07:29:05 UTC

Modules

    README

    select-prism

    A <select> is basically the UI representation of a union type or ADT.Using a Prism and it's data structure for a data transformation that's not quite isomorphic, we can use go from an ADT to a String and back like we'd prefer to do.

    import Html exposing (..)
    import Html.SelectPrism exposing (selectp)
    
    
    view : Model -> Html Msg
    view { selectedColor } =
        -- Right Here ↓
        selectp colorp ChangeColor selectedColor [] colorOptions
    
    
    colorOptions : List ( String, Color )
    colorOptions =
        [ ( "❤️  Red", Red )
        , ( "💙 Blue", Blue )
        , ( "💚 Green", Green )
        ]
    
    
    type alias Model =
        { selectedColor : Color }
    
    
    type Msg
        = ChangeColor (Result String Color)
    
    
    type Color
        = Red
        | Blue
        | Green
    
    
    {-| You the developer are responsible for this `Prism`s correctness
    -}
    colorp : Prism String Color
    colorp =
        let
            colorFromString : String -> Maybe Color
            colorFromString s =
                case s of
                    "red" ->
                        Just Red
    
                    "green" ->
                        Just Green
    
                    "blue" ->
                        Just Blue
    
                    _ ->
                        Nothing
    
            colorToString : Color -> String
            colorToString c =
                case c of
                    Red ->
                        "red"
    
                    Green ->
                        "green"
    
                    Blue ->
                        "blue"
        in
            -- Using `Prism` as a constructor
            Prism colorFromString colorToString
    

    Do check out the example and/or read my blog entry which goes into more depth.