Skip to content

Instantly share code, notes, and snippets.

@lfarroco
Last active October 24, 2017 16:53
Show Gist options
  • Save lfarroco/a648008e065bd6ffa3a30c4eb1e60676 to your computer and use it in GitHub Desktop.
Save lfarroco/a648008e065bd6ffa3a30c4eb1e60676 to your computer and use it in GitHub Desktop.
Elm - creating a list with multiple value Types
type MultiValue
= StringValue String
| IntegerValue Int
--... add other possibilities here
myList : List MultiValue
myList =
[ StringValue "a"
, IntegerValue 2
, StringValue "b"
]
{-| using these values
eg. multiply all numbers in the list per 2. leaves strings alone -}
newList =
myList
|> List.map
(\value ->
case value of
StringValue v ->
StringValue v
IntegerValue v ->
IntegerValue v * 2
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment