question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Absent semigroup should short-circut folds on first nothing

See original GitHub issue

Absent#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:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
jnapecommented, Mar 13, 2021

@corlaez Some combination of FoldRight.foldRight and lazyZip ought to do it. Something like:

FoldRight.foldRight(
        (maybeX, acc) -> maybeX.lazyZip(acc.fmap(maybeY -> maybeY.fmap(aSemigroup.flip()))),
        lazy(acc),
        rest);

Combine that with an initial match on the accumulator (so knowledge about a nothing() accumulator can be leveraged to elide the entire foldRight) and I think you’re home.

Makes sense?

0reactions
jnapecommented, Mar 15, 2021

Closed by #116

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found