Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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"
share|improve this question
1  
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 at 3:04
    
I find indentChar = liftA2 (||) isAlpha (=='(') more readable. –  Landei Jan 30 at 20:52

1 Answer 1

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.