Skip to content

Commit

Permalink
modules refactor WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
raulraja committed Dec 28, 2017
1 parent 398dfcf commit f9ddb47
Show file tree
Hide file tree
Showing 188 changed files with 2,506 additions and 1,370 deletions.
1 change: 1 addition & 0 deletions ank-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$parent.ext.kotlinVersion"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion"
compile "org.jetbrains:markdown:0.1.25"
compile project(':arrow-free')
compile project(':arrow-data')
compile "org.jetbrains.kotlin:kotlin-compiler:$parent.ext.kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-script-util:$parent.ext.kotlinVersion"
Expand Down
1 change: 1 addition & 0 deletions ank-core/src/main/kotlin/io/kategory/ank/algebra.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.arrow.ank

import arrow.*
import arrow.free.instances.FreeMonadInstance
import org.intellij.markdown.ast.ASTNode
import java.io.File

Expand Down
15 changes: 15 additions & 0 deletions arrow-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
compile project(':arrow-annotations')
kapt project(':arrow-annotations-processor')
kaptTest project(':arrow-annotations-processor')
compileOnly project(':arrow-annotations-processor')
testCompileOnly project(':arrow-annotations-processor')
testCompile "io.kotlintest:kotlintest:$kotlinTestVersion"
testCompile project(':arrow-syntax')
testCompile project(':arrow-test')
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
apply from: rootProject.file('gradle/generated-kotlin-sources.gradle')
apply plugin: 'kotlin-kapt'
4 changes: 4 additions & 0 deletions arrow-core/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Maven publishing configuration
POM_NAME=Arrow Core
POM_ARTIFACT_ID=arrow-core
POM_PACKAGING=jar
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package arrow.data

import arrow.*
package arrow

@Deprecated("arrow.data.Either is already right biased. This data type will be removed in future releases")
sealed class Disjunction<out L, out R> : EitherLike {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package arrow

import arrow.data.Disjunction
import arrow.data.LeftProjection
import arrow.data.RightProjection

typealias Right<A, B> = Either.Right<A, B>
typealias Left<A, B> = Either.Left<A, B>

Expand Down Expand Up @@ -240,10 +236,7 @@ inline fun <A, B> Either<A, B>.filterOrElse(crossinline predicate: (B) -> Boolea
*/
fun <A, B> Either<A, B>.contains(elem: B): Boolean = fold({ false }, { it == elem })

fun <A, B, C> Either<A, B>.ap(ff: EitherKind<A, (B) -> C>): Either<A, C> = ff.flatMap { f -> map(f) }.ev()

fun <G, A, B, C> Either<A, B>.traverse(f: (B) -> HK<G, C>, GA: Applicative<G>): HK<G, Either<A, C>> =
this.ev().fold({ GA.pure(Left(it)) }, { GA.map(f(it), { Right(it) }) })
fun <A, B, C> Either<A, B>.ap(ff: EitherKind<A, (B) -> C>): Either<A, C> = ff.ev().flatMap { f -> map(f) }.ev()

fun <A, B> Either<A, B>.combineK(y: EitherKind<A, B>): Either<A, B> =
when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package arrow.data
package arrow

interface EitherLike {
fun isLeft(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ package arrow
* overflows.
*/
@higherkind
@deriving(
Functor::class,
Applicative::class,
Monad::class,
Comonad::class,
Bimonad::class)
sealed class Eval<out A> : EvalKind<A> {

companion object {
Expand Down Expand Up @@ -68,149 +62,6 @@ sealed class Eval<out A> : EvalKind<A> {

val One: Eval<Int> = Now(1)

fun <A, B> merge(
op1: () -> A,
op2: () -> B): Eval<Tuple2<A, B>> =
applicative().tupled(
later(op1),
later(op2)
).ev()

fun <A, B, C> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C): Eval<Tuple3<A, B, C>> =
applicative().tupled(
later(op1),
later(op2),
later(op3)
).ev()

fun <A, B, C, D> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D): Eval<Tuple4<A, B, C, D>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4)
).ev()

fun <A, B, C, D, E> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D,
op5: () -> E): Eval<Tuple5<A, B, C, D, E>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4),
later(op5)
).ev()

fun <A, B, C, D, E, F> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D,
op5: () -> E,
op6: () -> F): Eval<Tuple6<A, B, C, D, E, F>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4),
later(op5),
later(op6)
).ev()

fun <A, B, C, D, E, F, G> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D,
op5: () -> E,
op6: () -> F,
op7: () -> G): Eval<Tuple7<A, B, C, D, E, F, G>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4),
later(op5),
later(op6),
later(op7)
).ev()

fun <A, B, C, D, E, F, G, H> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D,
op5: () -> E,
op6: () -> F,
op7: () -> G,
op8: () -> H): Eval<Tuple8<A, B, C, D, E, F, G, H>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4),
later(op5),
later(op6),
later(op7),
later(op8)
).ev()

fun <A, B, C, D, E, F, G, H, I> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D,
op5: () -> E,
op6: () -> F,
op7: () -> G,
op8: () -> H,
op9: () -> I): Eval<Tuple9<A, B, C, D, E, F, G, H, I>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4),
later(op5),
later(op6),
later(op7),
later(op8),
later(op9)
).ev()

fun <A, B, C, D, E, F, G, H, I, J> merge(
op1: () -> A,
op2: () -> B,
op3: () -> C,
op4: () -> D,
op5: () -> E,
op6: () -> F,
op7: () -> G,
op8: () -> H,
op9: () -> I,
op10: () -> J): Eval<Tuple10<A, B, C, D, E, F, G, H, I, J>> =
applicative().tupled(
later(op1),
later(op2),
later(op3),
later(op4),
later(op5),
later(op6),
later(op7),
later(op8),
later(op9),
later(op10)
).ev()
}

abstract fun value(): A
Expand All @@ -219,7 +70,7 @@ sealed class Eval<out A> : EvalKind<A> {

fun <B> map(f: (A) -> B): Eval<B> = flatMap { a -> Now(f(a)) }

fun <B> ap(ff: EvalKind<(A) -> B>): Eval<B> = ff.flatMap { f -> map(f) }.ev()
fun <B> ap(ff: EvalKind<(A) -> B>): Eval<B> = ff.ev().flatMap { f -> map(f) }.ev()

fun <B> flatMap(f: (A) -> EvalKind<B>): Eval<B> =
when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ interface FunctionK<F, G> {

}

fun <F, G, H> FunctionK<F, G>.or(h: FunctionK<H, G>): FunctionK<CoproductKindPartial<F, H>, G> =
object : FunctionK<CoproductKindPartial<F, H>, G> {
override fun <A> invoke(fa: CoproductKind<F, H, A>): HK<G, A> {
return fa.ev().fold(this@or, h)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ package arrow
fun <A> IdKind<A>.value(): A = this.ev().value

@higherkind
@deriving(
Functor::class,
Applicative::class,
Monad::class,
Comonad::class,
Bimonad::class,
Foldable::class,
Traverse::class)
data class Id<out A>(val value: A) : IdKind<A> {

inline fun <B> map(f: (A) -> B): Id<B> = Id(f(value))
Expand All @@ -21,13 +13,11 @@ data class Id<out A>(val value: A) : IdKind<A> {

fun <B> foldRight(lb: Eval<B>, f: (A, Eval<B>) -> Eval<B>): Eval<B> = f(this.ev().value, lb)

fun <G, B> traverse(f: (A) -> HK<G, B>, GA: Applicative<G>): HK<G, Id<B>> = GA.map(f(this.ev().value), { Id(it) })

fun <B> coflatMap(f: (IdKind<A>) -> B): Id<B> = this.ev().map({ f(this) })

fun extract(): A = this.ev().value

fun <B> ap(ff: IdKind<(A) -> B>): Id<B> = ff.flatMap { f -> map(f) }.ev()
fun <B> ap(ff: IdKind<(A) -> B>): Id<B> = ff.ev().flatMap { f -> map(f) }.ev()

companion object {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package arrow.data
package arrow

@Deprecated("arrow.data.Either is already right biased. This data type will be removed in future releases")
interface LeftLike : EitherLike {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package arrow.data
package arrow

import arrow.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ typealias None = Option.None
* are either an instance of $some or the object $none.
*/
@higherkind
@deriving(
Functor::class,
Applicative::class,
Monad::class,
Foldable::class,
Traverse::class,
TraverseFilter::class,
MonadFilter::class)
sealed class Option<out A> : OptionKind<A> {

companion object {
Expand Down Expand Up @@ -159,22 +151,6 @@ sealed class Option<out A> : OptionKind<A> {
}
}

fun <G, B> traverse(f: (A) -> HK<G, B>, GA: Applicative<G>): HK<G, Option<B>> =
this.ev().let { option ->
when (option) {
is Some -> GA.map(f(option.t), { Some(it) })
is None -> GA.pure(None)
}
}

fun <G, B> traverseFilter(f: (A) -> HK<G, Option<B>>, GA: Applicative<G>): HK<G, Option<B>> =
this.ev().let { option ->
when (option) {
is Some -> f(option.t)
is None -> GA.pure(None)
}
}

fun toList(): List<A> = fold(::emptyList, { listOf(it) })

infix fun <X> and(value: Option<X>): Option<X> = if (isEmpty()) {
Expand Down Expand Up @@ -216,7 +192,7 @@ fun <T> Option<T>.getOrElse(default: () -> T): T = fold({ default() }, { it })
*/
fun <A, B : A> OptionKind<B>.orElse(alternative: () -> Option<B>): Option<B> = if (ev().isEmpty()) alternative() else ev()

infix fun <T> OptionKind<T>.or(value: Option<T>): Option<T> = if (isEmpty()) {
infix fun <T> OptionKind<T>.or(value: Option<T>): Option<T> = if (ev().isEmpty()) {
value
} else {
ev()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ fun <A, B, C> PartialFunction<A, B>.andThen(f: (B) -> C): PartialFunction<A, C>
override fun invoke(a: A): C = f(this@andThen(a))
}

fun <A, B> case(ff: Tuple2<(A) -> Boolean, (A) -> B>): PartialFunction<A, B> =
object : PartialFunction<A, B>() {
override fun isDefinedAt(a: A): Boolean = ff.a(a)
override fun invoke(a: A): B = ff.b(a)
}

infix fun <A, B> ((A) -> Boolean).then(f: (A) -> B): Tuple2<(A) -> Boolean, (A) -> B> = Tuple2(this, f)

private class Lifted<A, B>(val pf: PartialFunction<A, B>) : (A) -> Option<B> {
override fun invoke(x: A): Option<B> = pf.andThen { Some(it) }.invokeOrElse(x, { None })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package arrow.data
package arrow

@Deprecated("arrow.data.Either is already right biased. This data type will be removed in future releases")
interface RightLike : EitherLike {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package arrow.data

import arrow.*
package arrow

@Deprecated("arrow.data.Either is right biased. This data type will be removed in future releases")
class RightProjection<out L, out R>(val e: Either<L, R>) {
Expand Down
Loading

0 comments on commit f9ddb47

Please sign in to comment.