Elm supports [1..100]
, but if I try ['a'..'z']
, the compiler gives me a type mismatch (expects a number, gets a Char). Is there any way do make this work?
Just create a range of numbers and map it to chars:
List.map Char.fromCode [97..122]
Edit, or as a function:
charRange : Char -> Char -> List Char
charRange from to =
List.map Char.fromCode [(Char.toCode from)..(Char.toCode to)]
charRange 'a' 'd' -- ['a','b','c','d'] : List Char
Edit, from elm 0.18 and up, List.range is finally a function:
charRange : Char -> Char -> List Char
charRange from to =
List.map Char.fromCode <| List.range (Char.toCode from) (Char.toCode to)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With