-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Type-classes for Prepend (Cons) and Append (Snoc) operations #4493
Comments
We have cats/core/src/main/scala/cats/NonEmptyAlternative.scala Lines 26 to 46 in ba48b63
|
Oh that's nice, didn't notice, thanks to @satorg 🙏 That seems to address my wish list above, and the intent of #1360 ✅ While on this topic, what about the co-operations to pull items out of containers, perhaps called "uncons" and "unsnoc", I see we have an implementation for |
You can use |
Also, perhaps as a work-around, there's |
|
Much as I disapprove of overusing Ed Kmett's name like a magic totem to justify a decision, he eloquently makes the case for Prepend and Append type-classes in this 2009 slide deck.
He calls them
Reducer
s, and the operations Cons and Snoc, but the idea is the same. He positions them as optimizations from Monoidal combine on the left and right:It's not a huge difference, but it adds up in a hot loop.
new
is the new slow, so I hear.It is now 2023 and we still need this. We see tutorials for
WriterT
(orValidation
) where people are emittingChain[String]
rather thanString
so that they can monoidally combine the incoming data.Another definition of Cons/Snoc typeclasses, again from Mr Kmett, is found in the Haskell Lens package.
I admit I've already asked for this before, but that issue got a bit distracted by another unrelated idea.
The text was updated successfully, but these errors were encountered: