Absent semigroup should short-circut folds on first nothing
See original GitHub issueAbsent#foldLeft
and #foldRight
should process the minimal number of elements of the inbound Iterable
necessary to produce the result, and since the semigroup treats nothing
as an annihilator, that means that nothing()
should cause a short-circuit. As a good heuristic, both Absent.<Unit>absent(Constantly::constantly).foldLeft(nothing(), repeat(just(UNIT)));
and Absent.<Unit>absent(Constantly::constantly).foldRight(nothing(), repeat(just(UNIT))).value();
should terminate.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Why is Maybe's Semigroup instance biased towards Just and ...
I would expect Nothing for the first two cases. Here is the alternative implementation (hopefully it is correct/lawful): instance Semigroup a => ...
Read more >Data.Foldable
The Foldable class represents data structures that can be reduced to a summary value one element at a time. Strict left-associative folds are...
Read more >arXiv:1806.01272v2 [math.FA] 2 Apr 2019
Abstract. This paper investigates a question of Radjavi: Which multiplicative semigroups in. B(H) have all their ideals selfadjoint (called ...
Read more >on the endomorphism semigroup (and category) of bounded ...
The first result is that every monoid is isomorphic to the monoid of all endomorphisms of a bounded lattice. One can also consider...
Read more >Working with non-monoids | F# for fun and profit
If you recall, for a proper monoid, we need three things to be true: closure, associativity, and identity. Each requirement can present a ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@corlaez Some combination of
FoldRight.foldRight
andlazyZip
ought to do it. Something like:Combine that with an initial
match
on the accumulator (so knowledge about anothing()
accumulator can be leveraged to elide the entirefoldRight
) and I think you’re home.Makes sense?
Closed by #116