Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:52:37+00:00 2026-06-11T18:52:37+00:00

I have looked at a number answers to questions here on Stack Overflow trying

  • 0

I have looked at a number answers to questions here on Stack Overflow trying to find a solution to my problem in using the Reactive Banana library. All the answers use some magic using ‘mapAccum’ that I can’t quite understand. Looking at the API documentation all I find is “Efficient combination of accumE and accumB.” which is not very helpful.

It seems that this function can be used to compare the values of a Behavior at the time of two consecutive events which is what I’d like to do. But I not clear how to make that work.

How exactly does mapAccum work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:52:38+00:00Added an answer on June 11, 2026 at 6:52 pm

    Notice that

    mapAccum :: acc -> Event t (acc -> (x, acc)) -> (Event t x, Behavior t acc)
    

    so it takes an initial value :: acc to accumulate on, and an Event which produces a function that
    updates that accumulated value whilst producing an output value ::x. (Typically you’d make such an event by partially applying some function via <$>.)
    As a result you get a new Event that fires your x values whenever they turn up and a Behaviour containing
    your current accumulated value.

    Use mapAccum if you have an event and you want to make a related behaviour and event.

    For example in your problem domain from your other question, suppose you have an event eTime :: Event t Int that fired erratically and you wanted to calculate eDeltaTime :: Event t Int for the differences and bTimeAgain :: Behaviour t Int
    for the currently used time:

    type Time = Int
    type DeltaTime = Time 
    
    getDelta :: Time -> Time -> (DeltaTime,Time)
    getDelta new old = (new-old,new)
    

    I could have written that getDelta new = \old -> (new-old,new) to make the next step clearer:

    deltaMaker :: Event t (Time -> (DeltaTime,Time))
    deltaMaker = getDelta <$> eTime
    
    (eDeltaT,bTimeAgain) = mapAccum 0 $ deltaMaker
    

    In this case, bTimeAgain would be a behaviour with the same value as the events in eTime. This happens
    because my getDelta function passes new straight through unchanged from eTime to the acc value.
    (If I wanted bTimeAgain on its own, I would have used stepper :: a -> Event t a -> Behaviour t a.)
    If I don’t need bTimeAgain, I could just write (eDeltaT,_) = mapAccum 0 $ deltaMaker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked at a large number of similar questions and none of the
I have looked for answer on other questions but I can't find one. My
I looked through the questions here but didn't find one that suited my case.
I have looked on the net as well as here but can't find an
I've looked at all the tutorials I can find, examined the questions on here
I have looked at questions like this , this , this and this ,
I have looked on the web to find a list of all Python keywords
I have looked here and from what I understand the following regex simply means
I have looked thoroughly, but I have not found the solution (or perhaps I
I've looked at a number of similar questions and so I'm demonstrating that I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.