-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mapWithState #122
Comments
Id do this with a fold normally..And IMO the final state value needs to be
exposed..
…On Sat., 21 May 2022, 10:41 am Luis Miguel Mejía Suárez, < ***@***.***> wrote:
The signature would be something like:
def mapWithState[S, B](init: S)(f: (S, A) => (S, B)): Col[B]
Is not as common as mapWithIndex but is kind of handy and is very hard to
implement generically without much boilerplate.
—
Reply to this email directly, view it on GitHub
<#122>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAXJZGCGN5PUGC6N3UYHGLVLAWLDANCNFSM5WQ747RA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
The thing is that now you have to construct the new collection by yourself which is redundant and error-prone but also it may be more inefficient than the underlying
Yeah, that is a good idea. PS: For the record, fs2 has this function, is called |
mapAccululate or mapAccumulation or statefulMap |
Just mentioned this here: https://users.scala-lang.org/t/idiomatic-map-combined-with-fold/9628, which lead me here. Had the need for this on several occasions. |
The signature would be something like:
Is not as common as
mapWithIndex
but is kind of handy and is very hard to implement generically without much boilerplate.The text was updated successfully, but these errors were encountered: