Skip to content

Instantly share code, notes, and snippets.

@allansideas
Last active July 7, 2017 20:15
Show Gist options
  • Save allansideas/9a2c513d1b4add499b1605abe5d69ed4 to your computer and use it in GitHub Desktop.
Save allansideas/9a2c513d1b4add499b1605abe5d69ed4 to your computer and use it in GitHub Desktop.
Trying to filter lists with mixed union types?
module Main exposing (..)
import Html exposing (Html, text, div, img)
import Html.Attributes exposing (src)
---- MODEL ----
type alias Model =
{}
init : ( Model, Cmd Msg )
init =
( {}, Cmd.none )
---- UPDATE ----
type Msg
= NoOp
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
( model, Cmd.none )
---- VIEW ----
type alias Record =
{ id : Int, nestedRecord : { string : String } }
type MyThing
= AString String
| AnInt Int
| ATuple ( String, Int )
| ARecord Record
listOfThings : List MyThing
listOfThings =
[ AString "AString"
, AnInt 1
, ATuple ( "Str", 2 )
, ARecord { id = 1, nestedRecord = { string = "String" } }
]
mapListFn =
List.filter
(\a ->
case a of
AString a ->
Debug.crash "Want to get to here"
AnInt a ->
Debug.crash "Or Here"
ATuple a ->
Debug.crash "Or even here"
ARecord a ->
Debug.crash "Also here!"
)
listOfThings
view : Model -> Html Msg
view model =
-- div []
-- [ text (unionFn (ARecord { id = 1, nestedRecord = { string = "String" } })) ]
div []
[ text (toString mapListFn) ]
---- PROGRAM ----
main : Program Never Model Msg
main =
Html.program
{ view = view
, init = init
, update = update
, subscriptions = always Sub.none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment