How to convert list list to list?

-1

In Haskell , I have the following problem:

I have the following list:

[[17,16,15],[14,13,12],[11,10,9],[8,7,6],[5,4,3],[2,1]]

And I would like to get

[17,16,14,13,11,10,8,7,5,4,2,1]

That is: from each 3-tuple, delete the last component. And if the tuple has fewer elements, do not delete any, as seen in the example.

I put another case, in case I have not explained myself well.

[[10,9,7],[7,5,5],[4,3,1],[0]] --> [10,9,7,5,4,3,0]
    
asked by aprendiendo-a-programar 07.01.2018 в 09:19
source

1 answer

0

You need to combine on the one hand a function that extracts the first two elements, as easy as making a mapping map (take 2) . On the other hand, you need the concatenation of results with concat . As it is so common to combine a map and a concat , there is a% combination of both called Data.List in concatMap :

import Data.List (concatMap)

f :: [[a]] -> [a]
f = concatMap (take 2)
    
answered by 07.01.2018 / 17:28
source