-
Notifications
You must be signed in to change notification settings - Fork 451
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
Add bind alias for Sequence operation in DSL #2978
Conversation
Kover Report
|
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt
Outdated
Show resolved
Hide resolved
I'm not a fan of reusing the |
I named it |
I would prefer that name, indeed. |
@serras one follow-up question, for |
That would be great! I thought that merely calling |
Calling I.e. listOf(1, 2).mapOrAccumulate {
if(it == 1) {
"fail-1".left().bind() // <-- short-circuits "current op"
"fail-1".left().bind() // this is not accumulated
} else {
listOf("fail-2".left(), "fail-2".left()).bindAll() // both get accumulated
}
} // Either.Left(NonEmptyList("fail-1", "fail-2", "fail-2")) So |
@nomisRev It makes sense to me, that due to the way types are resolved the |
@serras I am not sure I entirely follow your train of though.
Isn't this irrelevant? There is no other way for
Not sure I understood this comment. Is it the short-circuit behavior inside of accumulate that requires additional thinking? Or the fact that semantics of |
@@ -615,6 +616,31 @@ class EffectSpec : StringSpec({ | |||
} | |||
} | |||
|
|||
"bindAll fails on first error" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the two tests that show the behavior @serras
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few typos. Thanks, @nomisRev!
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Francisco Diaz <francisco.d@47deg.com> Co-authored-by: Imran Malic Settuba <46971368+i-walker@users.noreply.github.com>
public fun <A> Iterable<Option<A>>.sequence(): Option<List<A>> = | ||
traverse(::identity) | ||
let { l -> option { l.bindAll() } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the let is unnecessary here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option { this@sequence.bindAll() }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, indeed it's so that the ReplaceWith
is inline with the implementation body if people click through. Without let
ReplaceWith
horribly suffers from scope pollution 😞
let
should incur any perf penalty due to @InlineOnly
.
I was wondering why I got a Mentioned notification :D Good to hear my suggestion made it <3 On the mini-arrow I made for TypeScript we have |
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt
Outdated
Show resolved
Hide resolved
We have traverse separate but it’s called It’s indeed very useful, we’ve had it since before 1.0.0 though. Originally in And ofc, your feedback and knowledge is always super valuable @pakoito ❤️ Miss you 😘 |
…ise/RaiseAccumulate.kt
Adds
bind
as suggested by @pakoito in #2861.Updates
sequence
deprecation to point towards DSL.