map* for Data.List

Bulat Ziganshin bulat.ziganshin at gmail.com
Sat Nov 4 03:25:28 EST 2006


Hello libraries,

similar to mapFst and Co, we can define:

-- |Map various parts of list
mapHead f []      =  []
mapHead f (x:xs)  =  f x : xs

mapTail f []      =  []
mapTail f (x:xs)  =  x : map f xs

mapInit f []      =  []
mapInit f xs      =  map f (init xs) : last xs

mapLast f []      =  []
mapLast f xs      =  init xs : map f (last xs)


btw, two last operations may be a bit slow. it's possible to define
initLast function that returns both parts and still lazy?

-- 
Best regards,
 Bulat                          mailto:Bulat.Ziganshin at gmail.com



More information about the Libraries mailing list