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 7842721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:23:17+00:00 2026-06-02T16:23:17+00:00

What is the function that I should pass to ‘traverse’ (from the essence of

  • 0

What is the function that I should pass to ‘traverse’ (from the essence of the iterator pattern) such that I can accumulate state based on each of the original elements and then map based on the original elements and the state so far.

In ‘collect’ and ‘disperse’ only either the mapping depends on the state or the state depends on the element, but not both at the same time.

The table at http://etorreborre.blogspot.co.uk/2011/06/essence-of-iterator-pattern.html appears to say that I should use ‘traverse’ but traverse is the function that implements all the others, so I’m a bit lost.

  • 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-02T16:23:18+00:00Added an answer on June 2, 2026 at 4:23 pm

    When you use the traverse method with a function returning a State, you get exactly what you want:

       // a function using the current element and the previous state
       def function[S, T](s: S, t: T): R = // combine T and S
    
       // return a State instance to use as an Applicative with traverse
       def myState[T, S](t: T) = State[S, R]((s: S) => function(s, t))
    
       // a sequence to traverse
       val sequence: Seq[T] = ...
    
       // use the traverse method
       sequence.traverse(t => myState(t))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Effective STL tip 16, it says that we should avoid to pass iterator
I have a function specification that states it that should evaluate a polynomial function
Is there any way to specify that a function should be called when a
I'm having trouble with something that I understand should function out of the box
Let's say that some function returns object reference. How one should properly spell: this
I am trying to check that my function returns Some(x) testedFunc() |> should be
Many people have argued about function size. They say that functions in general should
Clearly, when GROUP BY clause used, columns that are not aggregate function should be
Should functions that act on and object, say to fill it out from xml,
I need a function that should give me a 10th or 100th array, for

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.