-
Notifications
You must be signed in to change notification settings - Fork 448
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
zipOrAccumulate
for Raise
#2919
Conversation
Kover Report
|
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.
Thanks. @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.
Couple of comments, many of the current signatures won't support suspend
as they're defined now.
Should we expose these APIs until arity-9 like we do for Either
?
*/ | ||
@RaiseDSL | ||
public fun <A, B, C> zipOrAccumulate( | ||
semigroup: Semigroup<@UnsafeVariance R>, |
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.
Pending on discussion to remove Semigroup
, not blocking for this PR.
Only blocking for 1.2.x release, if we move forward with it's deprecation than we should avoid it in this new signature.
when (val e = error) { | ||
is EmptyValue -> return results | ||
else -> raise(EmptyValue.unbox(e)) | ||
} |
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.
Nit: prefer expressions whenever possible.
when (val e = error) { | |
is EmptyValue -> return results | |
else -> raise(EmptyValue.unbox(e)) | |
} | |
return when (val e = error) { | |
is EmptyValue -> results | |
else -> raise(EmptyValue.unbox(e)) | |
} |
val results = mutableListOf<B>() | ||
forEach { | ||
fold<R, B, Unit>({ | ||
block(it) | ||
}, { newError -> | ||
error = semigroup.emptyCombine(error, newError) | ||
}, { | ||
results.add(it) | ||
}) | ||
} |
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.
Nit: use buildList
val results = mutableListOf<B>() | |
forEach { | |
fold<R, B, Unit>({ | |
block(it) | |
}, { newError -> | |
error = semigroup.emptyCombine(error, newError) | |
}, { | |
results.add(it) | |
}) | |
} | |
val results = buildList { | |
forEach { | |
fold<R, B, Unit>({ | |
block(it) | |
}, { newError -> | |
error = semigroup.emptyCombine(error, newError) | |
}, { | |
add(it) | |
}) | |
} | |
} |
* using the given [semigroup]. | ||
*/ | ||
@RaiseDSL | ||
public fun <A, B, C, D, E> zipOrAccumulate( |
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.
These need to be inline
to allow suspend
to pass through the lambdas.
public fun <A, B> Iterable<A>.mapOrAccumulate( | ||
semigroup: Semigroup<@UnsafeVariance R>, | ||
@BuilderInference block: Raise<R>.(A) -> B | ||
): List<B> { |
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.
This needs to be inline
to allow suspend
to pass through. Cries in context receivers 😭
public inline fun <A, B> Raise<R>.mapOrAccumulate(
semigroup: Semigroup<@UnsafeVariance R>,
list: Iterable<A>,
@BuilderInference block: Raise<R>.(A) -> B
): List<B> {
Supersedes #2880, targeting
main
instead ofarrow-2
.This PR adds both
zipOrAccumulate
andmapOrAccumulate
toRaise
, since the latter was not available in the 1.x branch.