I have this list
["0 1 1 0","1 0 1 0","1 1 0 1","0 0 1 0"]
and I want to convert every position of that list into a list of integers ie
[[0110],[1010],[1101],[0010]]
I have this list
["0 1 1 0","1 0 1 0","1 1 0 1","0 0 1 0"]
and I want to convert every position of that list into a list of integers ie
[[0110],[1010],[1101],[0010]]
intmap :: [String] -> [[Int]]
intmap x = map (\l -> map read (words l)) x
Shelling the code:
intmap
receives a list of Strings and returns a list of integer lists.
the lambda function \l -> map read (words l)
accepts a String and converts it to a list of elements separated by spaces, and then converts each element to an integer. This function is applied to each item in the list with map
.
The function can fail if the strings do not represent an integer. To expand it, exceptions or the Maybe monad could be used.