Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2461 closed proposal (fixed)

add Traversable generalizations of mapAccumL and mapAccumR

Reported by: ross Owned by:
Priority: normal Milestone:
Component: libraries/base Version:
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The proposal is to add the following functions to Data.Traversable, generalizing the list versions in Data.List:

-- |The 'mapAccumL' function behaves like a combination of 'fmap'
-- and 'foldl'; it applies a function to each element of a structure,
-- passing an accumulating parameter from left to right, and returning
-- a final value of this accumulator together with the new structure.
mapAccumL :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)

-- |The 'mapAccumR' function behaves like a combination of 'fmap'
-- and 'foldr'; it applies a function to each element of a structure,
-- passing an accumulating parameter from right to left, and returning
-- a final value of this accumulator together with the new structure.
mapAccumR :: Traversable t => (a -> b -> (a, c)) -> a -> t b -> (a, t c)

These functions are handy for things like labelling trees, zipping, etc.

Attachments (1)

mapAccum.patch (7.5 KB) - added by ross 9 years ago.
darcs patch

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by ross

Attachment: mapAccum.patch added

darcs patch

comment:1 Changed 9 years ago by ross

Resolution: fixed
Status: newclosed

There was limited discussion (with a large sidetrack on <>). A few in favour, no dissent.

comment:2 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.