The . operator composes functions, so they will be applied from right to left.
filter isLetter will remove all characters that are not letters from the string.
map (show . (flip (-)) 64 . ord . toUpper) Transforms each character to its position in the alphabet.
toUpper transforms the character to uppercase, so that we can substract 64 from it's code to know the position.
ord maps a character to its ASCII code.
(flip (-) 64) subtracts 64 from the character code. Since the code for 'A' is 65, this will give us the position in the alphabet starting at index 1. The way it works is it partially applies the second argument of the subtract operator to 64, i.e., this is equivalent to (\x -> x - 64) but fancier.
show maps any type deriving from Show (Int in this case) to String.
unwords joins a list of strings using space as a separator.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell
Some function composition sorcery in Haskell.
Explanation
The
.
operator composes functions, so they will be applied from right to left.filter isLetter
will remove all characters that are not letters from the string.map (show . (flip (-)) 64 . ord . toUpper)
Transforms each character to its position in the alphabet.toUpper
transforms the character to uppercase, so that we can substract 64 from it's code to know the position.ord
maps a character to its ASCII code.(flip (-) 64)
subtracts 64 from the character code. Since the code for'A'
is 65, this will give us the position in the alphabet starting at index 1. The way it works is it partially applies the second argument of the subtract operator to 64, i.e., this is equivalent to(\x -> x - 64)
but fancier.show
maps any type deriving fromShow
(Int
in this case) toString
.unwords
joins a list of strings using space as a separator.