I am trying to check if my set of chars in elm contains only valid chars. If a char is found that is invalid, I return those chars, separated by a comma. What I currently have tries to convert the string to a list of chars, then that list to a set of chars. Then diffs the set with a set of valid chars, not sure where to go after that, I have not written much in Elm before. If no diffs are found then return nothing.
validChars : Set.Set Char
validChars =
Set.fromList <| String.toList " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
validString : String -> Maybe String
validString x =
let
list =
String.toList x
set1 =
Set.fromList list
diffs=
Set.diff set1 validChars
if Set.isEmpty diffs == True
Nothing
The if statement doesn't work in Elms online compiler, it says it is looking for "in"
Your code has a few things wrong with it, here's a version that compiles.
Basically when it said it was looking for
in
, it wasn't wrong,in
is a necessary part of a function when you uselet
statements.