in reply to Re^2: 99 Problems in Perl6
in thread 99 Problems in Perl6
You know, we're getting pretty close to the terseness of Haskell, but (I think) it's still rather readable:
my $compress = sub ($x) { state $previous; $x ne $previous ?? $previous = $x !! return; }
And in Haskell:
compress :: Eq a => [a] -> [a] compress = map head . group
Update: as concise, but less "golfy":
my $compress = sub ($x) { state $previous; return $x ne $previous ?? $previous = $x !! (); }
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: 99 Problems in Perl6
by chromatic (Archbishop) on Dec 16, 2006 at 00:06 UTC | |
|
Re^4: 99 Problems in Perl6
by gaal (Parson) on Dec 15, 2006 at 22:39 UTC | |
by Ovid (Cardinal) on Dec 15, 2006 at 22:44 UTC | |
by gaal (Parson) on Dec 15, 2006 at 22:54 UTC | |
by TimToady (Parson) on Dec 15, 2006 at 23:31 UTC | |
by gaal (Parson) on Dec 15, 2006 at 23:44 UTC | |
|