Skip to content
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

Move code Arrow-Core #2403

Merged
merged 7 commits into from
May 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move code Arrow-Core
nomisRev committed May 20, 2021
commit 27e5e4df45f1e7a997a71a91c3079d55b2499d56
5 changes: 2 additions & 3 deletions arrow-libs/core/arrow-annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -10,10 +10,9 @@ apply from: "$ANIMALSNIFFER"

kotlin {
sourceSets {
jvmMain {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
api "io.kindedj:kindedj:$KINDEDJ_VERSION"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:$KOTLIN_VERSION"
}
}
}
5 changes: 5 additions & 0 deletions arrow-libs/core/arrow-continuations/build.gradle
Original file line number Diff line number Diff line change
@@ -12,6 +12,11 @@ apply plugin: 'kotlinx-atomicfu'

kotlin {
sourceSets {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:$KOTLIN_VERSION"
}
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package arrow.continuations.generic

/**
* A [Throwable] class intended for control flow.
* Instance of [ControlThrowable] should **not** be caught,
* and `arrow.core.NonFatal` does not catch this [Throwable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable].
*/
expect open class ControlThrowable() : Throwable
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
override suspend fun <A> shift(f: suspend RestrictedScope<R>.(DelimitedContinuation<A, R>) -> R): A =
suspendCoroutineUninterceptedOrReturn { continueMain ->
val delCont = SingleShotCont(continueMain, shiftFnContinuations)
assert(nextShift == null)
require(nextShift == null)
nextShift = suspend { this.f(delCont) }
COROUTINE_SUSPENDED
}
@@ -75,7 +75,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
*/
suspend fun <A, B> shiftCPS(f: suspend (DelimitedContinuation<A, B>) -> R, c: suspend DelimitedScope<B>.(A) -> B): Nothing =
suspendCoroutineUninterceptedOrReturn {
assert(nextShift == null)
require(nextShift == null)
nextShift = suspend { f(CPSCont(c)) }
COROUTINE_SUSPENDED
}
@@ -116,7 +116,7 @@ internal open class DelimContScope<R>(private val f: suspend RestrictedScope<R>.
// we can return directly if we never suspended/called shift
else return@invoke it as R
}
assert(resultVar !== EMPTY_VALUE)
require(resultVar !== EMPTY_VALUE)
// We need to finish the partially evaluated shift blocks by passing them our result.
// This will update the result via the continuations that now finish up
for (c in shiftFnContinuations.asReversed()) c.resume(resultVar as R)
Original file line number Diff line number Diff line change
@@ -77,14 +77,14 @@ internal open class MultiShotDelimContScope<R>(val f: suspend RestrictedScope<R>
suspendCoroutineUninterceptedOrReturn { continueMain ->
val c = MultiShotCont(continueMain, f, stack, shiftFnContinuations)
val s: suspend RestrictedScope<R>.() -> R = { this.func(c) }
assert(nextShift.compareAndSet(null, s))
require(nextShift.compareAndSet(null, s))
COROUTINE_SUSPENDED
}

suspend fun <A, B> shiftCPS(func: suspend DelimitedScope<R>.(DelimitedContinuation<A, B>) -> R, c: suspend DelimitedScope<B>.(A) -> B): Nothing =
suspendCoroutine {
val s: suspend DelimitedScope<R>.() -> R = { func(CPSCont(c)) }
assert(nextShift.compareAndSet(null, s))
require(nextShift.compareAndSet(null, s))
}

// This assumes RestrictSuspension or at least assumes the user to never reference the parent scope in f.
@@ -115,7 +115,7 @@ internal open class MultiShotDelimContScope<R>(val f: suspend RestrictedScope<R>
}
} else return@invoke it as R
}
assert(resultVar.value != null)
require(resultVar.value != null)
for (c in shiftFnContinuations.asReversed()) c.resume(resultVar.value!!)
return resultVar.value!!
}
Original file line number Diff line number Diff line change
@@ -2,5 +2,6 @@ package arrow.continuations.generic

/** Represents a unique identifier using object equality. */
internal class Token {
override fun toString(): String = "Token(${Integer.toHexString(hashCode())})"
@ExperimentalUnsignedTypes
override fun toString(): String = "Token(${hashCode().toUInt().toString(16)})"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

package arrow.continuations.generic

/**
* A [Throwable] class intended for control flow.
* Instance of [ControlThrowable] should **not** be caught,
* Instance of [ControlThrowable.kt] should **not** be caught,
* and `arrow.core.NonFatal` does not catch this [Throwable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable.kt].
*/
open class ControlThrowable : Throwable() {
actual open class ControlThrowable : Throwable() {
override fun fillInStackTrace(): Throwable = this
}
30 changes: 8 additions & 22 deletions arrow-libs/core/arrow-core-retrofit/build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.jvm"
id "org.jlleitschuh.gradle.ktlint"
}

apply from: "$SUB_PROJECT_MPP"
apply from: "$SUB_PROJECT"
apply from: "$TEST_COVERAGE"
apply from: "$DOC_CREATION"
apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER"

kotlin {
sourceSets {
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
compileOnly project(":arrow-core")
compileOnly "com.squareup.retrofit2:retrofit:$RETROFIT_VERSION"
}
}

jvmTest {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
runtimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION"
implementation project(":arrow-core-test")
implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
implementation "com.squareup.okhttp3:mockwebserver:$MOCKWEBSERVER_VERSION"
}
}
}
dependencies {
api project(":arrow-core")
api project(":arrow-continuations")
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLINX_COROUTINES_VERSION"
api "io.kotlintest:kotlintest-runner-junit5:$KOTLIN_TEST_VERSION", excludeArrow
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION"
}
9 changes: 7 additions & 2 deletions arrow-libs/core/arrow-core/build.gradle
Original file line number Diff line number Diff line change
@@ -13,12 +13,17 @@ apply from: "$ANIMALSNIFFER"

kotlin {
sourceSets {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:$KOTLIN_VERSION"
api project(":arrow-continuations")
api project(":arrow-annotations")
}
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
compileOnly "org.codehaus.mojo:animal-sniffer-annotations:1.19"
api project(":arrow-continuations")
api project(":arrow-annotations")
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package arrow.core

@PublishedApi
internal expect object ArrowCoreInternalException : RuntimeException
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.typeclasses.Monoid
import arrow.typeclasses.Semigroup
import kotlin.jvm.JvmName
import kotlin.jvm.JvmStatic

/**
*
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package arrow.core

import arrow.typeclasses.Monoid
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
import kotlin.jvm.JvmStatic

/**
* Eval is a monad which controls evaluation of a value or a computation that produces a value.
@@ -233,7 +233,7 @@ sealed class Eval<out A> {
is FlatMap<A> -> object : FlatMap<B>() {
override fun <S> start(): Eval<S> = (this@Eval).start()

@IgnoreJRERequirement
// @IgnoreJRERequirement
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this annotation is not needed anymore. AnimalSniffer seems to pass on this code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I'm going to review AnimalSniffer configuration because maybe it must be updated with the last change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, if we need it back we can turn it into a expect/actual annotation where native and JS have no-op annotations.

override fun <S> run(s: S): Eval<B> =
object : FlatMap<B>() {
override fun <S1> start(): Eval<S1> = (this@Eval).run(s) as Eval<S1>
@@ -381,15 +381,35 @@ fun <A, B, C, D> Eval<A>.zip(
c: Eval<C>,
map: (A, B, C) -> D
): Eval<D> =
zip(b, c, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, _, _, _, _, _, _, _ -> map(aa, bb, cc) }
zip(
b,
c,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit
) { aa, bb, cc, _, _, _, _, _, _, _ -> map(aa, bb, cc) }

fun <A, B, C, D, E> Eval<A>.zip(
b: Eval<B>,
c: Eval<C>,
d: Eval<D>,
map: (A, B, C, D) -> E
): Eval<E> =
zip(b, c, d, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, _, _, _, _, _, _ -> map(aa, bb, cc, dd) }
zip(
b,
c,
d,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit,
Eval.Now.unit
) { aa, bb, cc, dd, _, _, _, _, _, _ -> map(aa, bb, cc, dd) }

fun <A, B, C, D, E, F> Eval<A>.zip(
b: Eval<B>,
@@ -398,7 +418,15 @@ fun <A, B, C, D, E, F> Eval<A>.zip(
e: Eval<E>,
map: (A, B, C, D, E) -> F
): Eval<F> =
zip(b, c, d, e, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> map(aa, bb, cc, dd, ee) }
zip(b, c, d, e, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, _, _, _, _, _ ->
map(
aa,
bb,
cc,
dd,
ee
)
}

fun <A, B, C, D, E, F, G> Eval<A>.zip(
b: Eval<B>,
@@ -408,7 +436,16 @@ fun <A, B, C, D, E, F, G> Eval<A>.zip(
f: Eval<F>,
map: (A, B, C, D, E, F) -> G
): Eval<G> =
zip(b, c, d, e, f, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, _, _, _, _ -> map(aa, bb, cc, dd, ee, ff) }
zip(b, c, d, e, f, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, _, _, _, _ ->
map(
aa,
bb,
cc,
dd,
ee,
ff
)
}

fun <A, B, C, D, E, F, G, H> Eval<A>.zip(
b: Eval<B>,
@@ -419,7 +456,17 @@ fun <A, B, C, D, E, F, G, H> Eval<A>.zip(
g: Eval<G>,
map: (A, B, C, D, E, F, G) -> H
): Eval<H> =
zip(b, c, d, e, f, g, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, _, _, _ -> map(aa, bb, cc, dd, ee, ff, gg) }
zip(b, c, d, e, f, g, Eval.Now.unit, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, _, _, _ ->
map(
aa,
bb,
cc,
dd,
ee,
ff,
gg
)
}

fun <A, B, C, D, E, F, G, H, I> Eval<A>.zip(
b: Eval<B>,
@@ -431,7 +478,18 @@ fun <A, B, C, D, E, F, G, H, I> Eval<A>.zip(
h: Eval<H>,
map: (A, B, C, D, E, F, G, H) -> I
): Eval<I> =
zip(b, c, d, e, f, g, h, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, _, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh) }
zip(b, c, d, e, f, g, h, Eval.Now.unit, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, _, _ ->
map(
aa,
bb,
cc,
dd,
ee,
ff,
gg,
hh
)
}

fun <A, B, C, D, E, F, G, H, I, J> Eval<A>.zip(
b: Eval<B>,
@@ -444,7 +502,19 @@ fun <A, B, C, D, E, F, G, H, I, J> Eval<A>.zip(
i: Eval<I>,
map: (A, B, C, D, E, F, G, H, I) -> J
): Eval<J> =
zip(b, c, d, e, f, g, h, i, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, ii, _ -> map(aa, bb, cc, dd, ee, ff, gg, hh, ii) }
zip(b, c, d, e, f, g, h, i, Eval.Now.unit) { aa, bb, cc, dd, ee, ff, gg, hh, ii, _ ->
map(
aa,
bb,
cc,
dd,
ee,
ff,
gg,
hh,
ii
)
}

fun <A, B, C, D, E, F, G, H, I, J, K> Eval<A>.zip(
b: Eval<B>,
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import arrow.core.Ior.Left
import arrow.core.Ior.Right
import arrow.typeclasses.Monoid
import arrow.typeclasses.Semigroup
import kotlin.jvm.JvmStatic

typealias IorNel<A, B> = Ior<Nel<A>, B>

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package arrow.core
import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.typeclasses.Semigroup
import kotlin.jvm.JvmStatic

typealias Nel<A> = NonEmptyList<A>

@@ -201,13 +202,12 @@ class NonEmptyList<out A>(

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false

other as NonEmptyList<*>

if (all != other.all) return false

return true
other?.let {
if (it::class != this::class) return false
(other as NonEmptyList<*>)
if (all != other.all) return false
return true
} ?: return false
}

override fun hashCode(): Int =
Loading