Opened 6 years ago

Closed 6 years ago

Last modified 6 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: Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

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 6 years ago.
darcs patch

Download all attachments as: .zip

Change History (4)

Changed 6 years ago by ross

darcs patch

comment:1 Changed 6 years ago by ross

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:2 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:3 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.