-
-
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
Reducer typeclass #1360
Comments
I think which is also an Applicative on the result type. Algebird uses |
As explained in the slides, the key use for Reducer is efficient prepend/append of an element to a container. That doesn't look like the intent of Aggregator, which with 3 types and 3 interlinked operations, has a more complex structure (..that may also be useful, I just don't know). |
Aggregator has Reducer is an Aggregator with the final function (present it is called) being identity. Put another way, Aggregator (or Data.Fold.M) is Reducer combined with a free Functor. Some interesting examples of Aggregators: average of numbers: https://github.com/twitter/algebird/blob/develop/algebird-core/src/main/scala/com/twitter/algebird/AveragedValue.scala#L73 approximate unique counts with hyperloglog: https://github.com/twitter/algebird/blob/develop/algebird-core/src/main/scala/com/twitter/algebird/Aggregator.scala#L271 approximate percentile: https://github.com/twitter/algebird/blob/develop/algebird-core/src/main/scala/com/twitter/algebird/Aggregator.scala#L278 none of those work well without the final function to map from the monoid structure onto the value you want. |
👍 That Question is then, does a (maintained) cats version already exists somewhere and if not, where should this and potentially other related types live? |
@etorreborre has https://github.com/atnos-org/origami built
atop cats
Fold is similar to Aggregator in some ways, but allows monadic effects
while folding so its fold operation `(S, A) => M[S]` (folding down `A`s) is
non-parallelizable unlike the Semigroup in Aggregator.
|
By the way the |
Reducers model append and prepend operations on Monoidal containers.
Described on slide 9 of this talk by Kmett
See also haskell lib: https://hackage.haskell.org/package/monoids-0.3.2/docs/Data-Monoid-Reducer.html#t:Reducer
The text was updated successfully, but these errors were encountered: