-
Notifications
You must be signed in to change notification settings - Fork 7
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
WIP: upgrade to arrow 2.0 #83
Draft
hugomd
wants to merge
9
commits into
main
Choose a base branch
from
hugom-21-05-2024-arrow-2.0-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
314bce9
Upgrades arrow to 2.0.0-alpha.2
hugomd 7db978a
Removes tests for Validated
hugomd d101d9c
Backports ValidatedNel as Either<NonEmptyList<E>, A>
hugomd eaf9077
Backports Option's toValidatedNel to use Either<NonEmptyList<E>, A>
hugomd d3240c5
Uses the Raise DSL instead of continuations
hugomd e221cd8
Removes unused import
hugomd eaece31
Re-adds OutcomeEagerEffectScope to provide a suspended and blocking bind
hugomd be13f99
Adds arbNel in place of Arb.nonEmptyList
hugomd 01f96d5
Updates API declarations
hugomd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[versions] | ||
arrow = "1.2.4" | ||
arrow = "2.0.0-alpha.2" | ||
dokka = "1.9.20" | ||
junit = "5.10.2" | ||
kotest = "5.8.1" | ||
|
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
54 changes: 19 additions & 35 deletions
54
lib/src/main/kotlin/app/cash/quiver/continuations/OutcomeEagerEffectScope.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,42 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package app.cash.quiver.continuations | ||
|
||
import arrow.core.Either | ||
import arrow.core.continuations.EagerEffectScope | ||
import arrow.core.continuations.EffectScope | ||
import arrow.core.continuations.eagerEffect | ||
import arrow.core.continuations.effect | ||
import arrow.core.left | ||
import arrow.core.merge | ||
import arrow.core.right | ||
import app.cash.quiver.Absent | ||
import app.cash.quiver.Failure | ||
import app.cash.quiver.Outcome | ||
import app.cash.quiver.Present | ||
import arrow.core.Either | ||
import arrow.core.left | ||
import arrow.core.merge | ||
import arrow.core.raise.Raise | ||
import arrow.core.raise.eagerEffect | ||
import arrow.core.raise.effect | ||
import arrow.core.raise.fold | ||
import arrow.core.right | ||
|
||
// TODO(hugom): move this into an effect package, instead of continuations to align with arrow (?) | ||
@JvmInline | ||
value class OutcomeEagerEffectScope<E>(private val cont: EagerEffectScope<Either<Failure<E>, Absent>>) : | ||
EagerEffectScope<Either<Failure<E>, Absent>> { | ||
value class OutcomeEffectScope<E>(private val cont: Raise<Either<Failure<E>, Absent>>) : | ||
Raise<Either<Failure<E>, Absent>> { | ||
|
||
suspend fun <B> Outcome<E, B>.bind(): B = | ||
when (this) { | ||
is Absent -> shift(Absent.right()) | ||
is Failure -> shift(this.left()) | ||
Absent -> raise(Absent.right()) | ||
is Failure -> raise(this.left()) | ||
is Present -> value | ||
} | ||
|
||
@Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") | ||
override suspend fun <B> shift(r: Either<Failure<E>, Absent>): B = cont.shift(r) | ||
} | ||
|
||
@JvmInline | ||
value class OutcomeEffectScope<E>(private val cont: EffectScope<Either<Failure<E>, Absent>>) : | ||
EffectScope<Either<Failure<E>, Absent>> { | ||
|
||
public suspend fun <B> Outcome<E, B>.bind(): B = | ||
when (this) { | ||
Absent -> shift(Absent.right()) | ||
is Failure -> shift(this.left()) | ||
is Present -> value | ||
} | ||
|
||
override suspend fun <B> shift(r: Either<Failure<E>, Absent>): B = | ||
cont.shift(r) | ||
override fun raise(r: Either<Failure<E>, Absent>): Nothing = cont.raise(r) | ||
} | ||
|
||
@Suppress("ClassName") | ||
object outcome { | ||
inline fun <E, A> eager(crossinline f: suspend OutcomeEagerEffectScope<E>.() -> A): Outcome<E, A> = | ||
inline fun <E, A> eager(crossinline f: OutcomeEffectScope<E>.() -> A): Outcome<E, A> = | ||
eagerEffect { | ||
@Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL") | ||
f(OutcomeEagerEffectScope(this)) | ||
f.invoke(OutcomeEffectScope<E>(this)) | ||
}.fold({ it.merge() }, ::Present) | ||
|
||
suspend inline operator fun <E, A> invoke(crossinline f: suspend OutcomeEffectScope<E>.() -> A): Outcome<E, A> = | ||
effect { f(OutcomeEffectScope(this)) }.fold({ it.merge() }, ::Present) | ||
effect { | ||
f.invoke(OutcomeEffectScope<E>(this)) | ||
}.fold({ it.merge() }, ::Present) | ||
} |
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this can be removed, I contributed a
Raise
impl last year in theraise
package.https://github.com/cashapp/quiver/blob/main/lib/src/main/kotlin/app/cash/quiver/raise/OutcomeBuilder.kt
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.
Awesome! I'll look at migrating some of our existing codebases over to
OutcomeRaise
and see how it works out before removing 👍🏻