Last active
June 11, 2020 16:41
-
-
Save slouc/e76228fae43040ccc9240279831cf042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* `Foldable` folds things that form a `Monoid`; `fold` needs an identity and a binary op, and `Monoid` has both. | |
* `Reducible` reduces things that form a `Semigroup`; `reduce` only needs the binary op. | |
* Collections that can be empty (e.g. `List`) are `Foldable`. `fold` deals with emptiness by requiring an identity element. | |
* Collections that cannot be empty (e.g. `NonEmptyList`) are not only `Foldable`, but also `Reducible`. `reduce` is not good at dealing with emptiness (standard Scala's `reduce` blows up), but with non-empty collections that's not a problem. | |
Note: Folding a non-empty collection of elements that form a `Monoid` will use the `head` of collection as a starting element, and not `Monoid`'s identity. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment