[Haskell-cafe] how can I select all the 3-element-combination
out of a list efficiently
Andrew Coppin
andrewcoppin at btinternet.com
Sun May 20 05:23:09 EDT 2007
geniusfat wrote:
> hi dear haskell lover ;)
> what I want to do is simply this:
> select3 :: [a] -> [(a, a, a)]
> and how can it be done efficiently?
> thanks in advance!
>
What, as in
select3 [1..10] ->
[(1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,6,7),(6,7,8),(7,8,9),(8,9,10)]
?
How about like this:
select3 = map (\[x,y,z] -> (x,y,z)) . filter ((2 <) . length) . take 3
. tails
More information about the Haskell-Cafe
mailing list