Last active
October 24, 2017 16:53
-
-
Save lfarroco/a648008e065bd6ffa3a30c4eb1e60676 to your computer and use it in GitHub Desktop.
Elm - creating a list with multiple value Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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