How can I improve readability of this code? indentChar needs to be reused elsewhere.

toCoordinate = dropWhile ((||) <$> (not . indentChar) <*> (=='(')) >>> takeWhile(/= ' ') indentChar = (||) <$> isAlpha <*> (=='(')


Desired result:

*Parse> toCoordinate " \\--(my.coordinate - from outerspace)"
"my.coordinate"

• It would help to know what your input format is supposed to be. It looks pretty arbitrary, does "\\--" actually mean anything or are those completely arbitrary characters? Is the coordinate text, or will it really be comprised of digits? Also, you have mismatched parentheses in the definition of toCoordinate. – bisserlis Jan 26 '15 at 3:04
• I find indentChar = liftA2 (||) isAlpha (=='(') more readable. – Landei Jan 30 '15 at 20:52

The first thing I observe is that the dropWhile function argument is:

\x -> (not . indentChar) x || '(' == x

The comparison to '(' cancels out that same comparison in indentChar -- so the following definition of toCoordinate is identical in meaning:

toCoordinate = dropWhile (not . isAlpha) >>> takeWhile (/= ' ')

You did state that you need to use indentChar elsewhere -- but not using it here makes your code clearer.

Additionally, rather than use arrows, the above definition seems clearer to me when using function composition -- I would write it as:

toCoordinate = takeWhile (/= ' ') . dropWhile (not . isAlpha)