[Haskell-cafe] Re: Reversing a string of words: C# v Perl V Ruby
v Haskell
Donald Bruce Stewart
dons at cse.unsw.edu.au
Wed Dec 13 04:27:11 EST 2006
ulfn:
>
> On Dec 13, 2006, at 3:54 AM, Yitz Gale wrote:
>
> >Nice. Here is something similar:
> >
> >reverseWords = concat . reverse . groupBy eqsp
> > where eqsp x y = isSpace x == isSpace y
>
> This can be made even nicer using the 'on' function [1]:
>
> reverseWords = concat . reverse . groupBy ((==) `on` isSpace)
>
> [1] http://www.haskell.org/pipermail/libraries/2006-November/006156.html
Lambdabot trick(tm), use 'join' in the [] monad, instead of 'concat'
join . reverse . groupBy ((==) `on` isSpace)
-- Don
More information about the Haskell-Cafe
mailing list