diff --git a/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt b/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt new file mode 100644 index 000000000..00ee7d28a --- /dev/null +++ b/arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt @@ -0,0 +1,781 @@ +@file:Suppress("unused", "FunctionName") + +package arrow.core + +import arrow.typeclasses.Eq +import arrow.typeclasses.Monoid +import arrow.typeclasses.Semigroup +import arrow.typeclasses.Show +import kotlin.collections.foldRight as _foldRight + +inline fun Iterable.foldRight(initial: B, operation: (A, acc: B) -> B): B = + when (this) { + is List -> _foldRight(initial, operation) + else -> reversed().fold(initial) { acc, a -> operation(a, acc) } + } + +fun Iterable.ap(ff: Iterable<(A) -> B>): List = + flatMap { a -> ff.map { f -> f(a) } } + +inline fun Iterable.traverseEither(f: (A) -> Either): Either> = + foldRight>>(emptyList().right()) { a, acc -> + f(a).ap(acc.map { bs -> { b: B -> listOf(b) + bs } }) + } + +inline fun Iterable.flatTraverseEither(f: (A) -> Either>): Either> = + foldRight>>(emptyList().right()) { a, acc -> + f(a).ap(acc.map { bs -> { b: Iterable -> b + bs } }) + } + +inline fun Iterable.traverseEither_(f: (A) -> Either): Either { + val void = { _: Unit -> { _: Any? -> Unit } } + return foldRight>(Unit.right()) { a, acc -> + f(a).ap(acc.map(void)) + } +} + +fun Iterable>.sequenceEither(): Either> = + traverseEither(::identity) + +fun Iterable>>.flatSequenceEither(): Either> = + flatTraverseEither(::identity) + +fun Iterable>.sequenceEither_(): Either = + traverseEither_(::identity) + +inline fun Iterable.traverseValidated(semigroup: Semigroup, f: (A) -> Validated): Validated> = + foldRight>>(emptyList().valid()) { a, acc -> + f(a).ap(semigroup, acc.map { bs -> { b: B -> listOf(b) + bs } }) + } + +inline fun Iterable.flatTraverseValidated(semigroup: Semigroup, f: (A) -> Validated>): Validated> = + foldRight>>(emptyList().valid()) { a, acc -> + f(a).ap(semigroup, acc.map { bs -> { b: Iterable -> b + bs } }) + } + +inline fun Iterable.traverseValidated_(semigroup: Semigroup, f: (A) -> Validated): Validated = + foldRight>(Unit.valid()) { a, acc -> + f(a).ap(semigroup, acc.map { { Unit } }) + } + +fun Iterable>.sequenceValidated(semigroup: Semigroup): Validated> = + traverseValidated(semigroup, ::identity) + +fun Iterable>>.flatSequenceValidated(semigroup: Semigroup): Validated> = + flatTraverseValidated(semigroup, ::identity) + +fun Iterable>.sequenceValidated_(semigroup: Semigroup): Validated = + traverseValidated_(semigroup, ::identity) + +inline fun Iterable.map2(fb: Iterable, f: (Tuple2) -> Z): List = + flatMap { a -> + fb.map { b -> + f(Tuple2(a, b)) + } + } + +fun Iterable.mapConst(b: B): List = + map { b } + +fun Iterable.void(): List = + mapConst(Unit) + +fun List.foldRight(lb: Eval, f: (A, Eval) -> Eval): Eval { + fun loop(fa_p: List): Eval = when { + fa_p.isEmpty() -> lb + else -> f(fa_p.first(), Eval.defer { loop(fa_p.drop(1)) }) + } + + return Eval.defer { loop(this) } +} + +fun Iterable.reduceOrNull(initial: (A) -> B, operation: (acc: B, A) -> B): B? { + val iterator = this.iterator() + if (!iterator.hasNext()) return null + var accumulator: B = initial(iterator.next()) + while (iterator.hasNext()) { + accumulator = operation(accumulator, iterator.next()) + } + return accumulator +} + +inline fun List.reduceRightEvalOrNull( + initial: (A) -> B, + operation: (A, acc: Eval) -> Eval +): Eval { + val iterator = listIterator(size) + if (!iterator.hasPrevious()) return Eval.now(null) + var accumulator: Eval = Eval.now(initial(iterator.previous())) + while (iterator.hasPrevious()) { + accumulator = operation(iterator.previous(), accumulator) + } + return accumulator +} + +inline fun List.reduceRightNull( + initial: (A) -> B, + operation: (A, acc: B) -> B +): B? { + val iterator = listIterator(size) + if (!iterator.hasPrevious()) return null + var accumulator: B = initial(iterator.previous()) + while (iterator.hasPrevious()) { + accumulator = operation(iterator.previous(), accumulator) + } + return accumulator +} + +/** + * Returns a [List>] containing the zipped values of the two lists with null for padding. + * + * Example: + * ```kotlin:ank:playground + * import arrow.core.* + * + * //sampleStart + * val padRight = listOf(1, 2).padZip(listOf("a")) // Result: [Tuple2(1, "a"), Tuple2(2, null)] + * val padLeft = listOf(1).padZip(listOf("a", "b")) // Result: [Tuple2(1, "a"), Tuple2(null, "b")] + * val noPadding = listOf(1, 2).padZip(listOf("a", "b")) // Result: [Tuple2(1, "a"), Tuple2(2, "b")] + * //sampleEnd + * + * fun main() { + * println("padRight = $padRight") + * println("padLeft = $padLeft") + * println("noPadding = $noPadding") + * } + * ``` + */ +fun Iterable.padZip(other: Iterable): List> = + align(other) { ior -> + ior.fold( + { it toT null }, + { null toT it }, + { a, b -> a toT b } + ) + } + +/** + * Returns a [ListK] containing the result of applying some transformation `(A?, B?) -> C` + * on a zip. + * + * Example: + * ```kotlin:ank:playground + * import arrow.core.* + * + * //sampleStart + * val padZipRight = listOf(1, 2).padZip(listOf("a")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(2, null)] + * val padZipLeft = listOf(1).padZip(listOf("a", "b")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(null, "b")] + * val noPadding = listOf(1, 2).padZip(listOf("a", "b")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(2, "b")] + * //sampleEnd + * + * fun main() { + * println("padZipRight = $padZipRight") + * println("padZipLeft = $padZipLeft") + * println("noPadding = $noPadding") + * } + * ``` + */ +inline fun Iterable.padZip(other: Iterable, fa: (A?, B?) -> C): List = + padZip(other).map { fa(it.a, it.b) } + +/** + * Returns a [List] containing the result of applying some transformation `(A?, B) -> C` + * on a zip, excluding all cases where the right value is null. + * + * Example: + * ```kotlin:ank:playground + * import arrow.core.* + * + * //sampleStart + * val left = listOf(1, 2).leftPadZip(listOf("a")) { l, r -> l toT r } // Result: [Tuple2(1, "a")] + * val right = listOf(1).leftPadZip(listOf("a", "b")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(null, "b")] + * val both = listOf(1, 2).leftPadZip(listOf("a", "b")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(2, "b")] + * //sampleEnd + * + * fun main() { + * println("left = $left") + * println("right = $right") + * println("both = $both") + * } + * ``` + */ +inline fun Iterable.leftPadZip(other: Iterable, fab: (A?, B) -> C): List = + padZip(other) { a: A?, b: B? -> b?.let { fab(a, it) } }.mapNotNull(::identity) + +/** + * Returns a [List>] containing the zipped values of the two listKs + * with null for padding on the left. + * + * Example: + * ```kotlin:ank:playground + * import arrow.core.* + * + * //sampleStart + * val padRight = listOf(1, 2).leftPadZip(listOf("a")) // Result: [Tuple2(1, "a")] + * val padLeft = listOf(1).leftPadZip(listOf("a", "b")) // Result: [Tuple2(1, "a"), Tuple2(null, "b")] + * val noPadding = listOf(1, 2).leftPadZip(listOf("a", "b")) // Result: [Tuple2(1, "a"), Tuple2(2, "b")] + * //sampleEnd + * + * fun main() { + * println("left = $left") + * println("right = $right") + * println("both = $both") + * } + * ``` + */ +fun Iterable.leftPadZip(other: Iterable): List> = + this.leftPadZip(other) { a, b -> a toT b } + +/** + * Returns a [List] containing the result of applying some transformation `(A, B?) -> C` + * on a zip, excluding all cases where the left value is null. + * + * Example: + * ```kotlin:ank:playground + * import arrow.core.* + * + * //sampleStart + * val left = listOf(1, 2).rightPadZip(listOf("a")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(null, "b")] + * val right = listOf(1).rightPadZip(listOf("a", "b")) { l, r -> l toT r } // Result: [Tuple2(1, "a")] + * val both = listOf(1, 2).rightPadZip(listOf("a", "b")) { l, r -> l toT r } // Result: [Tuple2(1, "a"), Tuple2(2, "b")] + * //sampleEnd + * + * fun main() { + * println("left = $left") + * println("right = $right") + * println("both = $both") + * } + * ``` + */ +inline fun Iterable.rightPadZip(other: Iterable, fa: (A, B?) -> C): List = + other.leftPadZip(this) { a, b -> fa(b, a) } + +/** + * Returns a [List>] containing the zipped values of the two listKs + * with null for padding on the right. + * + * Example: + * ```kotlin:ank:playground + * import arrow.core.* + * + * //sampleStart + * val padRight = listOf(1, 2).rightPadZip(listOf("a")) // Result: [Tuple2(1, "a"), Tuple2(2, null)] + * val padLeft = listOf(1).rightPadZip(listOf("a", "b")) // Result: [Tuple2(1, "a")] + * val noPadding = listOf(1, 2).rightPadZip(listOf("a", "b")) // Result: [Tuple2(1, "a"), Tuple2(2, "b")] + * //sampleEnd + * + * fun main() { + * println("left = $left") + * println("right = $right") + * println("both = $both") + * } + * ``` + */ +fun Iterable.rightPadZip(other: Iterable): List> = + this.rightPadZip(other) { a, b -> a toT b } + +fun Iterable.show(SA: Show): String = "[" + + joinToString(", ") { SA.run { it.show() } } + "]" + +@Suppress("UNCHECKED_CAST") +private tailrec fun go( + buf: MutableList, + f: (A) -> Iterable>, + v: List> +) { + if (v.isNotEmpty()) { + when (val head: Either = v.first()) { + is Either.Right -> { + buf += head.b + go(buf, f, v.drop(1)) + } + is Either.Left -> go(buf, f, (f(head.a) + v.drop(1))) + } + } +} + +fun tailRecMIterable(a: A, f: (A) -> Iterable>): List { + val buf = mutableListOf() + go(buf, f, f(a).toList()) + return ListK(buf) +} + +/** + * Combines two structures by taking the union of their shapes and combining the elements with the given function. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf("A", "B").align(listOf(1, 2, 3)) { + * "$it" + * } + * //sampleEnd + * println(result) + * } + * ``` + */ +inline fun Iterable.align(b: Iterable, fa: (Ior) -> C): List = + this.align(b).map(fa) + +/** + * Combines two structures by taking the union of their shapes and using Ior to hold the elements. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf("A", "B").align(listOf(1, 2, 3)) + * //sampleEnd + * println(result) + * } + * ``` + */ +fun Iterable.align(b: Iterable): List> = + alignRec(this, b) + +@Suppress("NAME_SHADOWING") +private fun alignRec(ls: Iterable, rs: Iterable): List> { + val ls = if (ls is List) ls else ls.toList() + val rs = if (rs is List) rs else rs.toList() + return when { + ls.isEmpty() -> rs.map { it.rightIor() } + rs.isEmpty() -> ls.map { it.leftIor() } + else -> listOf(Ior.Both(ls.first(), rs.first())) + alignRec(ls.drop(1), rs.drop(1)) + } +} + +/** + * aligns two structures and combine them with the given [Semigroup.combine] + */ +fun Iterable.salign( + SG: Semigroup, + other: Iterable +): Iterable = SG.run { + align(other) { + it.fold(::identity, ::identity) { a, b -> + a.combine(b) + } + } +} + +/** + * unzips the structure holding the resulting elements in an `Tuple2` + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf("A" toT 1, "B" toT 2).k().unzip() + * //sampleEnd + * println(result) + * } + * ``` + */ +fun Iterable>.unzip(): Tuple2, List> = + fold(emptyList() toT emptyList()) { (l, r), x -> + l + x.a toT r + x.b + } + +/** + * after applying the given function unzip the resulting structure into its elements. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf("A:1", "B:2", "C:3").k().unzip { e -> + * e.split(":").let { + * it.first() toT it.last() + * } + * } + * //sampleEnd + * println(result) + * } + * ``` + */ +inline fun Iterable.unzip(fc: (C) -> Tuple2): Tuple2, List> = + map(fc).unzip() + +/** + * splits a union into its component parts. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf(("A" toT 1).bothIor(), ("B" toT 2).bothIor(), "C".leftIor()) + * .unalign() + * //sampleEnd + * println(result) + * } + * ``` + */ +fun Iterable>.unalign(): Tuple2, List> = + fold(emptyList() toT emptyList()) { (l, r), x -> + x.fold( + { l + it toT r }, + { l toT r + it }, + { a, b -> l + a toT r + b } + ) + } + +/** + * after applying the given function, splits the resulting union shaped structure into its components parts + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf(1, 2, 3).unalign { + * it.leftIor() + * } + * //sampleEnd + * println(result) + * } + * ``` + */ +inline fun Iterable.unalign(fa: (C) -> Ior): Tuple2, List> = + map(fa).unalign() + +fun Iterable.product(fb: Iterable): List> = + fb.ap(map { a: A -> { b: B -> Tuple2(a, b) } }) + +fun Iterable.combineAll(MA: Monoid): A = MA.run { + this@combineAll.fold(empty()) { acc, a -> + acc.combine(a) + } +} + +/** + * attempt to split the computation, giving access to the first result. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf("A", "B", "C").split() + * //sampleEnd + * println(result) + * } + */ +fun Iterable.split(): Tuple2, A>? = + firstOrNull()?.let { first -> + Tuple2(tail(), first) + } + +fun Iterable.tail(): List = + drop(1) + +/** + * interleave both computations in a fair way. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val tags = List(10) { "#" } + * val result = + * tags.interleave(listOf("A", "B", "C")) + * //sampleEnd + * println(result) + * } + */ +fun Iterable.interleave(other: Iterable): List = + this.split()?.let { (fa, a) -> + listOf(a) + other.interleave(fa) + } ?: other.toList() + +/** + * Fair conjunction. Similarly to interleave + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf(1,2,3).unweave { i -> listOf("$i, ${i + 1}") } + * //sampleEnd + * println(result) + * } + */ +fun Iterable.unweave(ffa: (A) -> Iterable): List = + split()?.let { (fa, a) -> + ffa(a).interleave(fa.unweave(ffa)) + } ?: emptyList() + +/** + * Logical conditional. The equivalent of Prolog's soft-cut. + * If its first argument succeeds at all, then the results will be + * fed into the success branch. Otherwise, the failure branch is taken. + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result = + * listOf(1,2,3).ifThen(listOf("empty")) { i -> + * listOf("$i, ${i + 1}") + * } + * //sampleEnd + * println(result) + * } + */ +inline fun Iterable.ifThen(fb: Iterable, ffa: (A) -> Iterable): Iterable = + split()?.let { (fa, a) -> + ffa(a) + fa.flatMap(ffa) + } ?: fb.toList() + +fun Iterable>.uniteEither(): List = + flatMap { either -> + either.fold({ emptyList() }, { b -> listOf(b) }) + } + +fun Iterable>.uniteValidated(): List = + flatMap { validated -> + validated.fold({ emptyList() }, { b -> listOf(b) }) + } + +/** + * Separate the inner [Either] values into the [Either.Left] and [Either.Right]. + * + * @receiver Iterable of Validated + * @return a tuple containing List with [Either.Left] and another List with its [Either.Right] values. + */ +fun Iterable>.separateEither(): Tuple2, List> { + val asep = flatMap { gab -> gab.fold({ listOf(it) }, { emptyList() }) } + val bsep = flatMap { gab -> gab.fold({ emptyList() }, { listOf(it) }) } + return Tuple2(asep, bsep) +} + +/** + * Separate the inner [Validated] values into the [Validated.Invalid] and [Validated.Valid]. + * + * @receiver Iterable of Validated + * @return a tuple containing List with [Validated.Invalid] and another List with its [Validated.Valid] values. + */ +fun Iterable>.separateValidated(): Tuple2, List> { + val asep = flatMap { gab -> gab.fold({ listOf(it) }, { emptyList() }) } + val bsep = flatMap { gab -> gab.fold({ emptyList() }, { listOf(it) }) } + return Tuple2(asep, bsep) +} + +fun Iterable>.flatten(): List = + flatMap(::identity) + +inline fun Iterable.ifM(ifFalse: () -> Iterable, ifTrue: () -> Iterable): List = + flatMap { bool -> + if (bool) ifTrue() else ifFalse() + } + +fun Iterable>.selectM(f: Iterable<(A) -> B>): List = + flatMap { it.fold({ a -> f.map { ff -> ff(a) } }, { b -> listOf(b) }) } + +/** + * Applies [f] to an [A] inside [Iterable] and returns the [List] structure with a tuple of the [A] value and the + * computed [B] value as result of applying [f] + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * val result = + * //sampleStart + * listOf("Hello").fproduct { "$it World" } + * //sampleEnd + * println(result) + * } + * ``` + */ +inline fun Iterable.fproduct(f: (A) -> B): List> = + map { a -> Tuple2(a, f(a)) } + +/** + * Pairs [B] with [A] returning a List> + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * val result = + * //sampleStart + * listOf("Hello", "Hello2").tupleLeft("World") + * //sampleEnd + * println(result) + * } + * ``` + */ +fun Iterable.tupleLeft(b: B): List> = + map { a -> Tuple2(b, a) } + +/** + * Pairs [A] with [B] returning a List> + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * val result = + * //sampleStart + * listOf("Hello").tupleRight("World") + * //sampleEnd + * println(result) + * } + * ``` + */ +fun Iterable.tupleRight(b: B): List> = + map { a -> Tuple2(a, b) } + +/** + * Given [A] is a sub type of [B], re-type this value from Iterable to Iterable + * + * Kind -> Kind + * + * ```kotlin:ank:playground + * import arrow.core.* + * + * fun main(args: Array) { + * //sampleStart + * val result: Iterable = + * listOf("Hello World").widen() + * //sampleEnd + * println(result) + * } + * ``` + */ +fun Iterable.widen(): Iterable = + this + +fun List.widen(): List = + this + +fun Iterable.fold(MA: Monoid): A = MA.run { + this@fold.fold(empty()) { acc, a -> + acc.combine(a) + } +} + +fun Iterable.foldMap(MB: Monoid, f: (A) -> B): B = MB.run { + this@foldMap.fold(empty()) { acc, a -> + acc.combine(f(a)) + } +} + +fun listEq(EQA: Eq): Eq> = + ListEq(EQA) + +private class ListEq(private val EQA: Eq) : Eq> { + override fun List.eqv(b: List): Boolean = + eqv(EQA, b) +} + +fun Iterable.eqv(EQA: Eq, other: Iterable): Boolean = EQA.run { + if (this is Collection<*> && other is Collection && this.size != other.size) false + else { + zip(other) { a, b -> a.eqv(b) } + .fold(true) { acc, bool -> acc && bool } + } +} + +fun Iterable.neqv(EQA: Eq, other: Iterable): Boolean = + !eqv(EQA, other) + +fun Iterable.crosswalk(f: (A) -> Iterable): List> = + fold(emptyList()) { bs, a -> + f(a).align(bs) { ior -> + ior.fold( + { listOf(it) }, + ::identity, + { l, r -> listOf(l) + r } + ) + } + } + +fun Iterable.crosswalkMap(f: (A) -> Map): Map> = + fold(emptyMap()) { bs, a -> + f(a).align(bs) { ior -> + ior.fold( + { listOf(it) }, + ::identity, + { l, r -> listOf(l) + r } + ) + } + } + +fun Iterable.crosswalkNull(f: (A) -> B?): List? = + fold?>(emptyList()) { bs, a -> + Ior.fromNullables(f(a), bs)?.fold( + { listOf(it) }, + ::identity, + { l, r -> listOf(l) + r } + ) + } + +@PublishedApi +internal val unit: List = + listOf(Unit) + +@JvmName("product3") +fun Iterable>.product(other: Iterable): List> = + map2(other) { (ab, c) -> Tuple3(ab.a, ab.b, c) } + +@JvmName("product4") +fun Iterable>.product(other: Iterable): List> = + map2(other) { (abc, d) -> Tuple4(abc.a, abc.b, abc.c, d) } + +@JvmName("product5") +fun Iterable>.product(other: Iterable): List> = + map2(other) { (abcd, e) -> Tuple5(abcd.a, abcd.b, abcd.c, abcd.d, e) } + +@JvmName("product6") +fun Iterable>.product(other: Iterable): List> = + map2(other) { (abcde, f) -> Tuple6(abcde.a, abcde.b, abcde.c, abcde.d, abcde.e, f) } + +@JvmName("product7") +fun Iterable>.product( + other: Iterable +): List> = + map2(other) { (abcdef, g) -> Tuple7(abcdef.a, abcdef.b, abcdef.c, abcdef.d, abcdef.e, abcdef.f, g) } + +@JvmName("product8") +fun Iterable>.product( + other: Iterable +): List> = + map2(other) { (abcdefg, h) -> Tuple8(abcdefg.a, abcdefg.b, abcdefg.c, abcdefg.d, abcdefg.e, abcdefg.f, abcdefg.g, h) } + +@JvmName("product9") +fun Iterable>.product( + other: Iterable +): List> = + map2(other) { (abcdefgh, i) -> Tuple9(abcdefgh.a, abcdefgh.b, abcdefgh.c, abcdefgh.d, abcdefgh.e, abcdefgh.f, abcdefgh.g, abcdefgh.h, i) } + +@JvmName("product10") +fun Iterable>.product( + other: Iterable +): List> = + map2(other) { (abcdefghi, j) -> Tuple10(abcdefghi.a, abcdefghi.b, abcdefghi.c, abcdefghi.d, abcdefghi.e, abcdefghi.f, abcdefghi.g, abcdefghi.h, abcdefghi.i, j) } + +fun Iterable.replicate(n: Int): List> = + if (n <= 0) emptyList() + else toList().let { l -> List(n) { l } } + +fun Iterable.replicate(n: Int, MA: Monoid): List = + if (n <= 0) listOf(MA.empty()) + else ListK.mapN(this@replicate, replicate(n - 1, MA)) { a, xs -> MA.run { a + xs } } diff --git a/arrow-core-data/src/main/kotlin/arrow/core/List.kt b/arrow-core-data/src/main/kotlin/arrow/core/List.kt new file mode 100644 index 000000000..d3ecbe8a4 --- /dev/null +++ b/arrow-core-data/src/main/kotlin/arrow/core/List.kt @@ -0,0 +1,119 @@ +package arrow.core + +import arrow.typeclasses.Hash +import arrow.typeclasses.Monoid +import arrow.typeclasses.Order +import arrow.typeclasses.Show +import arrow.typeclasses.defaultSalt +import arrow.typeclasses.hashWithSalt + +fun listHash(HA: Hash): Hash> = + ListHash(HA) + +private class ListHash(private val HA: Hash) : Hash> { + override fun List.hash(): Int = hash(HA) + override fun List.hashWithSalt(salt: Int): Int = hashWithSalt(HA, salt) +} + +fun List.hash(HA: Hash): Int = + hashWithSalt(HA, defaultSalt) + +fun List.hashWithSalt(HA: Hash, salt: Int): Int = HA.run { + fold(salt) { hash, x -> x.hashWithSalt(hash) }.hashWithSalt(size) +} + +fun List.compare(OA: Order, b: List): Ordering = OA.run { + align(b) { ior -> ior.fold({ GT }, { LT }, { a1, a2 -> a1.compare(a2) }) } + .fold(Ordering.monoid()) +} + +/** + * Check if [this@lt] is `lower than` [b] + * + * @receiver object to compare with [b] + * @param b object to compare with [this@lt] + * @returns true if [this@lt] is `lower than` [b] and false otherwise + */ +fun List.lt(OA: Order, b: List): Boolean = + compare(OA, b) == LT + +/** + * Check if [this@lte] is `lower than or equal to` [b] + * + * @receiver object to compare with [b] + * @param b object to compare with [this@lte] + * @returns true if [this@lte] is `lower than or equal to` [b] and false otherwise + */ +fun List.lte(OA: Order, b: List): Boolean = + compare(OA, b) != GT + +/** + * Check if [this@gt] is `greater than` [b] + * + * @receiver object to compare with [b] + * @param b object to compare with [this@gt] + * @returns true if [this@gt] is `greater than` [b] and false otherwise + */ +fun List.gt(OA: Order, b: List): Boolean = + compare(OA, b) == GT + +/** + * Check if [this@gte] is `greater than or equal to` [b] + * + * @receiver object to compare with [b] + * @param b object to compare with [this@gte] + * @returns true if [this@gte] is `greater than or equal to` [b] and false otherwise + */ +fun List.gte(OA: Order, b: List): Boolean = + compare(OA, b) != LT + +/** + * Determines the maximum of [this@max] and [b] in terms of order. + * + * @receiver object to compare with [b] + * @param b object to compare with [this@max] + * @returns the maximum [this@max] if it is greater than [b] or [b] otherwise + */ +fun List.max(OA: Order, b: List): List = + if (gt(OA, b)) this else b + +/** + * Determines the minimum of [this@min] and [b] in terms of order. + * + * @receiver object to compare with [b] + * @param b object to compare with [this@min] + * @returns the minimum [this@min] if it is less than [b] or [b] otherwise + */ +fun List.min(OA: Order, b: List): List = + if (lt(OA, b)) this else b + +/** + * Sorts [this@sort] and [b] in terms of order. + * + * @receiver object to compare with [b] + * @param b object to compare with [this@sort] + * @returns a sorted [Tuple2] of [this@sort] and [b]. + */ +fun List.sort(OA: Order, b: List): Tuple2, List> = + if (gte(OA, b)) Tuple2(this, b) else Tuple2(b, this) + +fun listOrder(OA: Order): Order> = + ListOrder(OA) + +private class ListOrder(private val OA: Order) : Order> { + override fun List.compare(b: List): Ordering = compare(OA, b) +} + +fun listMonoid(): Monoid> = + ListMonoid as Monoid> + +object ListMonoid : Monoid> { + override fun empty(): List = emptyList() + override fun List.combine(b: List): List = this + b +} + +fun listShow(SA: Show): Show> = + object : Show> { + override fun List.show(): String = + show(SA) + } diff --git a/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt b/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt index 9a9383857..959757972 100644 --- a/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt +++ b/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt @@ -472,6 +472,233 @@ data class ListK(private val list: List) : ListKOf, List by list rs.isEmpty() -> ls.map { it.leftIor() } else -> listOf(Ior.Both(ls.first(), rs.first())) + alignRec(ls.drop(1), rs.drop(1)) } + + inline fun mapN( + b: Iterable, + c: Iterable, + map: (B, C) -> D + ): List = + mapN(b, c, unit, unit, unit, unit, unit, unit, unit, unit) { b, c, _, _, _, _, _, _, _, _ -> map(b, c) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + map: (B, C, D) -> E + ): List = + mapN(b, c, d, unit, unit, unit, unit, unit, unit, unit) { b, c, d, _, _, _, _, _, _, _ -> map(b, c, d) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + map: (B, C, D, E) -> F + ): List = + mapN(b, c, d, e, unit, unit, unit, unit, unit, unit) { b, c, d, e, _, _, _, _, _, _ -> map(b, c, d, e) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + map: (B, C, D, E, F) -> G + ): List = + mapN(b, c, d, e, f, unit, unit, unit, unit, unit) { b, c, d, e, f, _, _, _, _, _ -> map(b, c, d, e, f) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + map: (B, C, D, E, F, G) -> H + ): List = + mapN(b, c, d, e, f, g, unit, unit, unit, unit) { b, c, d, e, f, g, _, _, _, _ -> map(b, c, d, e, f, g) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + map: (B, C, D, E, F, G, H) -> I + ): List = + mapN(b, c, d, e, f, g, h, unit, unit, unit) { b, c, d, e, f, g, h, _, _, _ -> map(b, c, d, e, f, g, h) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + i: Iterable, + map: (B, C, D, E, F, G, H, I) -> J + ): List = + mapN(b, c, d, e, f, g, h, i, unit, unit) { b, c, d, e, f, g, h, i, _, _ -> map(b, c, d, e, f, g, h, i) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + i: Iterable, + j: Iterable, + map: (B, C, D, E, F, G, H, I, J) -> K + ): List = + mapN(b, c, d, e, f, g, h, i, j, unit) { b, c, d, e, f, g, h, i, j, _ -> map(b, c, d, e, f, g, h, i, j) } + + inline fun mapN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + i: Iterable, + j: Iterable, + k: Iterable, + map: (B, C, D, E, F, G, H, I, J, K) -> L + ): List = + b.flatMap { bb -> + c.flatMap { cc -> + d.flatMap { dd -> + e.flatMap { ee -> + f.flatMap { ff -> + g.flatMap { gg -> + h.flatMap { hh -> + i.flatMap { ii -> + j.flatMap { jj -> + k.map { kk -> + map(bb, cc, dd, ee, ff, gg, hh, ii, jj, kk) + } + } + } + } + } + } + } + } + } + } + + fun tupledN( + b: Iterable, + c: Iterable + ): List> = + mapN(b, c) { b, c -> + Tuple2(b, c) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable + ): List> = + mapN(b, c, d) { b, c, d -> + Tuple3(b, c, d) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable + ): List> = + mapN(b, c, d, e) { b, c, d, e -> + Tuple4(b, c, d, e) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable + ): List> = + mapN(b, c, d, e, f) { b, c, d, e, f -> + Tuple5(b, c, d, e, f) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable + ): List> = + mapN(b, c, d, e, f, g) { b, c, d, e, f, g -> + Tuple6(b, c, d, e, f, g) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable + ): List> = + mapN(b, c, d, e, f, g, h) { b, c, d, e, f, g, h -> + Tuple7(b, c, d, e, f, g, h) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + i: Iterable + ): List> = + mapN(b, c, d, e, f, g, h, i) { b, c, d, e, f, g, h, i -> + Tuple8(b, c, d, e, f, g, h, i) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + i: Iterable, + j: Iterable + ): List> = + mapN(b, c, d, e, f, g, h, i, j) { b, c, d, e, f, g, h, i, j -> + Tuple9(b, c, d, e, f, g, h, i, j) + } + + fun tupledN( + b: Iterable, + c: Iterable, + d: Iterable, + e: Iterable, + f: Iterable, + g: Iterable, + h: Iterable, + i: Iterable, + j: Iterable, + k: Iterable + ): List> = + mapN(b, c, d, e, f, g, h, i, j, k) { b, c, d, e, f, g, h, i, j, k -> + Tuple10(b, c, d, e, f, g, h, i, j, k) + } } } @@ -482,9 +709,3 @@ fun List.k(): ListK = ListK(this) fun listKOf(vararg elements: A): ListK = listOf(*elements).k() - -fun Iterable.mapConst(b: B): List = - map { b } - -fun Iterable.void(): List = - mapConst(Unit) diff --git a/arrow-core-data/src/main/kotlin/arrow/core/Ordering.kt b/arrow-core-data/src/main/kotlin/arrow/core/Ordering.kt index b3016b15d..799951206 100644 --- a/arrow-core-data/src/main/kotlin/arrow/core/Ordering.kt +++ b/arrow-core-data/src/main/kotlin/arrow/core/Ordering.kt @@ -119,7 +119,7 @@ private object OrderingMonoid : Monoid { override fun empty(): Ordering = EQ override fun Ordering.combine(b: Ordering): Ordering = - this.combine(b) + this + b } @Suppress("EXTENSION_SHADOWED_BY_MEMBER") diff --git a/arrow-core-data/src/main/kotlin/arrow/core/map.kt b/arrow-core-data/src/main/kotlin/arrow/core/map.kt index 385840058..94c6f7c51 100644 --- a/arrow-core-data/src/main/kotlin/arrow/core/map.kt +++ b/arrow-core-data/src/main/kotlin/arrow/core/map.kt @@ -3,3 +3,11 @@ package arrow.core object MapInstances object SortedMapInstances + +fun Map.align(b: Map): Map> = + (keys + b.keys).mapNotNull { key -> + Ior.fromNullables(this@align[key], b[key])?.let { key to it } + }.toMap() + +fun Map.align(b: Map, fa: (Ior) -> C): Map = + this.align(b).mapValues { (_, v) -> fa(v) } diff --git a/arrow-core-data/src/test/kotlin/arrow/core/IterableTest.kt b/arrow-core-data/src/test/kotlin/arrow/core/IterableTest.kt new file mode 100644 index 000000000..229d2d827 --- /dev/null +++ b/arrow-core-data/src/test/kotlin/arrow/core/IterableTest.kt @@ -0,0 +1,98 @@ +package arrow.core + +import arrow.core.extensions.eq +import arrow.core.test.UnitSpec +import arrow.core.test.laws.equalUnderTheLaw +import io.kotlintest.properties.Gen +import io.kotlintest.properties.forAll +import kotlin.math.max +import kotlin.math.min + +class IterableTest : UnitSpec() { + init { + "can align lists with different lengths" { + forAll(Gen.list(Gen.bool()), Gen.list(Gen.bool())) { a, b -> + a.align(b).size == max(a.size, b.size) + } + + forAll(Gen.list(Gen.bool()), Gen.list(Gen.bool())) { a, b -> + a.align(b).take(min(a.size, b.size)).all { + it.isBoth + } + } + + forAll(Gen.list(Gen.bool()), Gen.list(Gen.bool())) { a, b -> + a.align(b).drop(min(a.size, b.size)).all { + if (a.size < b.size) { + it.isRight + } else { + it.isLeft + } + } + } + } + + "leftPadZip (with map)" { + forAll(Gen.list(Gen.int()), Gen.list(Gen.int())) { a, b -> + val left = a.map { it } + List(max(0, b.count() - a.count())) { null } + val right = b.map { it } + List(max(0, a.count() - b.count())) { null } + + val result = a.leftPadZip(b) { a, b -> a toT b } + + result == left.zip(right) { l, r -> l toT r }.filter { it.b != null } + } + } + + "leftPadZip (without map)" { + forAll(Gen.list(Gen.int()), Gen.list(Gen.int())) { a, b -> + val left = a.map { it } + List(max(0, b.count() - a.count())) { null } + val right = b.map { it } + List(max(0, a.count() - b.count())) { null } + + val result = a.leftPadZip(b) + + result == left.zip(right) { l, r -> l toT r }.filter { it.b != null } + } + } + + "rightPadZip (without map)" { + forAll(Gen.list(Gen.int()), Gen.list(Gen.int())) { a, b -> + val left = a.map { it } + List(max(0, b.count() - a.count())) { null } + val right = b.map { it } + List(max(0, a.count() - b.count())) { null } + + val result = a.rightPadZip(b) + + result == left.zip(right) { l, r -> l toT r }.filter { it.a != null } && + result.map { it.a }.equalUnderTheLaw(a, listEq(Int.eq())) + } + } + + "rightPadZip (with map)" { + forAll(Gen.list(Gen.int()), Gen.list(Gen.int())) { a, b -> + val left = a.map { it } + List(max(0, b.count() - a.count())) { null } + val right = b.map { it } + List(max(0, a.count() - b.count())) { null } + + val result = a.rightPadZip(b) { a, b -> a toT b } + + result == left.zip(right) { l, r -> l toT r }.filter { it.a != null } && + result.map { it.a }.equalUnderTheLaw(a, listEq(Int.eq())) + } + } + + "padZip" { + forAll(Gen.list(Gen.int()), Gen.list(Gen.int())) { a, b -> + val left = a.map { it } + List(max(0, b.count() - a.count())) { null } + val right = b.map { it } + List(max(0, a.count() - b.count())) { null } + a.padZip(b) { l, r -> Ior.fromNullables(l, r) } == left.zip(right) { l, r -> Ior.fromNullables(l, r) } + } + } + + "padZipWithNull" { + forAll(Gen.list(Gen.int()), Gen.list(Gen.int())) { a, b -> + val left = a.map { it } + List(max(0, b.count() - a.count())) { null } + val right = b.map { it } + List(max(0, a.count() - b.count())) { null } + + a.padZip(b) == left.zip(right) { l, r -> l toT r } + } + } + } +} diff --git a/arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt b/arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt index 86d8227e5..ae924bdc9 100644 --- a/arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt +++ b/arrow-core-data/src/test/kotlin/arrow/core/ListKTest.kt @@ -3,7 +3,6 @@ package arrow.core import arrow.Kind import arrow.core.extensions.eq import arrow.core.extensions.hash -import arrow.core.extensions.list.zip.zipWith import arrow.core.extensions.listk.align.align import arrow.core.extensions.listk.applicative.applicative import arrow.core.extensions.listk.crosswalk.crosswalk @@ -19,14 +18,12 @@ import arrow.core.extensions.listk.monoid.monoid import arrow.core.extensions.listk.monoidK.monoidK import arrow.core.extensions.listk.monoidal.monoidal import arrow.core.extensions.listk.order.order -import arrow.core.extensions.listk.semialign.semialign import arrow.core.extensions.listk.semigroupK.semigroupK import arrow.core.extensions.listk.show.show import arrow.core.extensions.listk.traverse.traverse import arrow.core.extensions.listk.unalign.unalign import arrow.core.extensions.listk.unzip.unzip import arrow.core.extensions.order -import arrow.core.extensions.listk.zip.zipWith import arrow.core.extensions.option.eq.eq import arrow.core.extensions.show import arrow.core.test.UnitSpec @@ -47,13 +44,10 @@ import arrow.core.test.laws.ShowLaws import arrow.core.test.laws.TraverseLaws import arrow.core.test.laws.UnalignLaws import arrow.core.test.laws.UnzipLaws -import arrow.core.test.laws.equalUnderTheLaw import arrow.typeclasses.Eq import io.kotlintest.properties.Gen import io.kotlintest.properties.forAll import io.kotlintest.shouldBe -import kotlin.math.max -import kotlin.math.min import arrow.core.extensions.list.monad.flatten as monadFlatten import arrow.core.extensions.listk.monad.flatten as kMonadFlatten @@ -128,164 +122,6 @@ class ListKTest : UnitSpec() { a.kMonadFlatten() shouldBe listOf(0, 1, 2, 3, 4, 5) } - "can align lists with different lengths" { - forAll(Gen.listK(Gen.bool()), Gen.listK(Gen.bool())) { a, b -> - ListK.semialign().run { - align(a, b).fix().size == max(a.size, b.size) - } - } - - forAll(Gen.listK(Gen.bool()), Gen.listK(Gen.bool())) { a, b -> - ListK.semialign().run { - align(a, b).fix().take(min(a.size, b.size)).all { - it.isBoth - } - } - } - - forAll(Gen.listK(Gen.bool()), Gen.listK(Gen.bool())) { a, b -> - ListK.semialign().run { - align(a, b).fix().drop(min(a.size, b.size)).all { - if (a.size < b.size) { - it.isRight - } else { - it.isLeft - } - } - } - } - } - - "lpadzip" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - - val result = - a.lpadZip(b) - - result.map { it.b }.equalUnderTheLaw(b, ListK.eq(Int.eq())) - } - } - - "lpadzipwith" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - - val result = - a.lpadZipWith(b) { a, b -> - a toT b - } - - result.map { it.b }.equalUnderTheLaw(b, ListK.eq(Int.eq())) - } - } - - "leftPadZip (with map)" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { it }.k() + List(max(0, b.count() - a.count())) { null }.k() - val right = b.map { it }.k() + List(max(0, a.count() - b.count())) { null }.k() - - val result = - a.leftPadZip(b) { a, b -> - a toT b - } - - result == left.zipWith(right) { l, r -> l toT r }.filter { it.b != null } - } - } - - "leftPadZip (without map)" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { it }.k() + List(max(0, b.count() - a.count())) { null }.k() - val right = b.map { it }.k() + List(max(0, a.count() - b.count())) { null }.k() - - val result = a.leftPadZip(b) - - result == left.zipWith(right) { l, r -> l toT r }.filter { it.b != null } - } - } - - "rpadzip" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - - val result = - a.rpadZip(b) - - result.map { it.a }.equalUnderTheLaw(a, ListK.eq(Int.eq())) - } - } - - "rightPadZip (without map)" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { it }.k() + List(max(0, b.count() - a.count())) { null }.k() - val right = b.map { it }.k() + List(max(0, a.count() - b.count())) { null }.k() - - val result = a.rightPadZip(b) - - result == left.zipWith(right) { l, r -> l toT r }.filter { it.a != null } && - result.map { it.a }.equalUnderTheLaw(a, ListK.eq(Int.eq())) - } - } - - "rpadzipwith" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - - val result = - a.rpadZipWith(b) { a, b -> - a toT b - } - - result.map { it.a }.equalUnderTheLaw(a, ListK.eq(Int.eq())) - } - } - - "rightPadZip (with map)" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { it }.k() + List(max(0, b.count() - a.count())) { null }.k() - val right = b.map { it }.k() + List(max(0, a.count() - b.count())) { null }.k() - - val result = - a.rightPadZip(b) { a, b -> - a toT b - } - - result == left.zipWith(right) { l, r -> l toT r }.filter { it.a != null } && - result.map { it.a }.equalUnderTheLaw(a, ListK.eq(Int.eq())) - } - } - - "padZip" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { Some(it) }.k() + List(max(0, b.count() - a.count())) { None }.k() - val right = b.map { Some(it) }.k() + List(max(0, a.count() - b.count())) { None }.k() - - a.padZip(b) == left.zipWith(right) { l, r -> l toT r } - } - } - - "padZipWith" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { Some(it) }.k() + List(max(0, b.count() - a.count())) { None }.k() - val right = b.map { Some(it) }.k() + List(max(0, a.count() - b.count())) { None }.k() - a.padZipWith(b) { l, r -> Ior.fromOptions(l, r) } == left.zipWith(right) { l, r -> Ior.fromOptions(l, r) } - } - } - - "padZip (with map)" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { it }.k() + List(max(0, b.count() - a.count())) { null }.k() - val right = b.map { it }.k() + List(max(0, a.count() - b.count())) { null }.k() - a.padZip(b) { l, r -> Ior.fromNullables(l, r) } == left.zipWith(right) { l, r -> Ior.fromNullables(l, r) } - } - } - - "padZipWithNull" { - forAll(Gen.listK(Gen.int()), Gen.listK(Gen.int())) { a, b -> - val left = a.map { it }.k() + List(max(0, b.count() - a.count())) { null }.k() - val right = b.map { it }.k() + List(max(0, a.count() - b.count())) { null }.k() - - a.padZipWithNull(b) == left.zipWith(right) { l, r -> l toT r } - } - } - "filterMap() should map list and filter out None values" { forAll(Gen.listK(Gen.int())) { listk -> listk.filterMap { diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/align/ListKAlign.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/align/ListKAlign.kt new file mode 100644 index 000000000..f12bf35eb --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/align/ListKAlign.kt @@ -0,0 +1,33 @@ +package arrow.core.extensions.list.align + +import arrow.core.extensions.ListKAlign +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("empty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("emptyList()")) +fun empty(): List = + emptyList() + +/** + * cached extension + */ +@PublishedApi() +internal val align_singleton: ListKAlign = object : arrow.core.extensions.ListKAlign {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Align typeclasses is deprecated. Use concrete methods on List") + inline fun align(): ListKAlign = align_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/alternative/ListKAlternative.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/alternative/ListKAlternative.kt new file mode 100644 index 000000000..114660026 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/alternative/ListKAlternative.kt @@ -0,0 +1,126 @@ +package arrow.core.extensions.list.alternative + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.None +import arrow.core.Option +import arrow.core.SequenceK +import arrow.core.Some +import arrow.core.extensions.ListKAlternative +import arrow.core.fix +import kotlin.Boolean +import kotlin.Function0 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("some") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("This method results in StackOverflow") +fun List.some(): List> = + arrow.core.extensions.list.alternative.List.alternative().run { + arrow.core.ListK(this@some).some() as kotlin.collections.List> +} + +@JvmName("many") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("This method results in StackOverflow") +fun List.many(): List> = + arrow.core.extensions.list.alternative.List.alternative().run { + arrow.core.ListK(this@many).many() as kotlin.collections.List> + } + +@JvmName("alt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1")) +infix fun List.alt(arg1: List): List = + this + arg1 + +@JvmName("orElse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1")) +fun List.orElse(arg1: List): List = + this + arg1 + +@JvmName("combineK") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1")) +fun List.combineK(arg1: List): List = + this + arg1 + +@JvmName("optional") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map(::Some) + listOf(None)", "arrow.core.Some", "arrow.core.None")) +fun List.optional(): List> = + map(::Some) + listOf(None) + +@JvmName("guard") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("if (arg0) listOf(Unit) else emptyList()")) +fun guard(arg0: Boolean): List = + if (arg0) listOf(Unit) else emptyList() + +@JvmName("lazyOrElse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1()")) +fun List.lazyOrElse(arg1: Function0>): List = + this + arg1().fix() + +/** + * cached extension + */ +@PublishedApi() +internal val alternative_singleton: ListKAlternative = object : + arrow.core.extensions.ListKAlternative {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Alternative typeclasses is deprecated. Use concrete methods on List") + inline fun alternative(): ListKAlternative = alternative_singleton +} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/applicative/ListKApplicative.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/applicative/ListKApplicative.kt new file mode 100644 index 000000000..2d1beb57e --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/applicative/ListKApplicative.kt @@ -0,0 +1,85 @@ +package arrow.core.extensions.list.applicative + +import arrow.core.extensions.ListKApplicative +import arrow.typeclasses.Monoid +import arrow.core.replicate as _replicate +import kotlin.Function1 +import kotlin.collections.map as _map +import kotlin.Int +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("just1") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("listOf(this)")) +fun A.just(): List = + listOf(this) + +@JvmName("unit") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("listOf(Unit)")) +fun unit(): List = + listOf(Unit) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map(arg1)")) +fun List.map(arg1: Function1): List = + _map(arg1) + +@JvmName("replicate") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("replicate(arg1)", "arrow.core.replicate")) +fun List.replicate(arg1: Int): List> = + _replicate(arg1) + +@JvmName("replicate") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("replicate(arg1, arg2)", "arrow.core.replicate")) +fun List.replicate(arg1: Int, arg2: Monoid): List = + _replicate(arg1, arg2) + +/** + * cached extension + */ +@PublishedApi() +internal val applicative_singleton: ListKApplicative = object : + arrow.core.extensions.ListKApplicative {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") + inline fun applicative(): ListKApplicative = applicative_singleton +} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/apply/ListKApply.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/apply/ListKApply.kt new file mode 100644 index 000000000..150fbaa19 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/apply/ListKApply.kt @@ -0,0 +1,873 @@ +package arrow.core.extensions.list.apply + +import arrow.Kind +import arrow.core.Eval +import arrow.core.ap as _ap +import arrow.core.map2 as _map2 +import arrow.core.product as _product +import kotlin.collections.flatMap as _flatMap +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.Tuple10 +import arrow.core.Tuple2 +import arrow.core.Tuple3 +import arrow.core.Tuple4 +import arrow.core.Tuple5 +import arrow.core.Tuple6 +import arrow.core.Tuple7 +import arrow.core.Tuple8 +import arrow.core.Tuple9 +import arrow.core.extensions.ListKApply +import arrow.core.fix +import arrow.core.k +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("ap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("_ap(arg1)", "arrow.core.ap")) +fun List.ap(arg1: List>): List = + _ap(arg1) + +@JvmName("apEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("arg1.map { this.ap(it.fix()) }.map { it.k() }", "arrow.core.k", "arrow.core.fix")) +fun List.apEval(arg1: Eval>>): Eval> = + arg1.map { this.ap(it.fix()) }.map { it.k() } + +@JvmName("map2Eval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("apEval(arg1.map { it.fix().map { b -> { a: A -> arg2(Tuple2(a, b)) } } })", "arrow.core.k", "arrow.core.Tuple2")) +fun List.map2Eval(arg1: Eval>, arg2: Function1, Z>): + Eval> = + apEval(arg1.map { it.fix().map { b -> { a: A -> arg2(Tuple2(a, b)) } } }) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1).map(arg2)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: Function1, Z> +): List = + ListK.tupledN(arg0, arg1).map(arg2) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1).map(arg2)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: Function1, Z> +): List = + ListK.tupledN(arg0, arg1).map(arg2) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2).map(arg3)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2).map(arg3) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2).map(arg3)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2).map(arg3) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3).map(arg4)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3).map(arg4) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3).map(arg4)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3).map(arg4) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4).map(arg5)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4).map(arg5) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4).map(arg5)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4).map(arg5) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5).map(arg6)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5).map(arg6) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5).map(arg6)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5).map(arg6) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6).map(arg7)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6).map(arg7) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6).map(arg7)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6).map(arg7) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7).map(arg8)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7).map(arg8) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7).map(arg8)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7).map(arg8) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).map(arg9)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List, + arg9: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).map(arg9) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).map(arg9)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List, + arg9: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).map(arg9) + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).map(arg10)", "arrow.core.tupledN")) +fun map( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List, + arg9: List, + arg10: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).map(arg10) + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).map(arg10)", "arrow.core.tupledN")) +fun mapN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List, + arg9: List, + arg10: Function1, Z> +): List = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).map(arg10) + +@JvmName("map2") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map2(arg1, arg2)", "arrow.core.map2")) +fun List.map2(arg1: List, arg2: Function1, Z>): List = + _map2(arg1, arg2) + +@JvmName("product") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List.product(arg1: List): List> = + _product(arg1) + +@JvmName("product1") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): List> = + _product(arg1) + +@JvmName("product2") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): List> = + _product(arg1) + +@JvmName("product3") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): List> = + _product(arg1) + +@JvmName("product4") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): List> = + _product(arg1) + +@JvmName("product5") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): List> = + _product(arg1) + +@JvmName("product6") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): + List> = + _product(arg1) + +@JvmName("product7") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): + List> = + _product(arg1) + +@JvmName("product8") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List>.product(arg1: List): + List> = + _product(arg1) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1)", "arrow.core.tupledN")) +fun tupled(arg0: List, arg1: List): List> = + ListK.tupledN(arg0, arg1) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1)", "arrow.core.tupledN")) +fun tupledN(arg0: List, arg1: List): List> = + ListK.tupledN(arg0, arg1) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List +): List> = + ListK.tupledN(arg0, arg1, arg2) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List +): List> = + ListK.tupledN(arg0, arg1, arg2) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)", "arrow.core.tupledN")) +fun tupled( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List, + arg9: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)", "arrow.core.tupledN")) +fun tupledN( + arg0: List, + arg1: List, + arg2: List, + arg3: List, + arg4: List, + arg5: List, + arg6: List, + arg7: List, + arg8: List, + arg9: List +): List> = + ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + +@JvmName("followedBy") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("flatMap { arg1 }")) +fun List.followedBy(arg1: List): List = + _flatMap { arg1 } + +@JvmName("apTap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.mapN(this, arg1) { left, _ -> left }", "arrow.core.mapN")) +fun List.apTap(arg1: List): List = + ListK.mapN(this, arg1) { left, _ -> left } + +/** + * cached extension + */ +@PublishedApi() +internal val apply_singleton: ListKApply = object : arrow.core.extensions.ListKApply {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Apply typeclasses is deprecated. Use concrete methods on List") + inline fun apply(): ListKApply = apply_singleton +} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/crosswalk/ListKCrosswalk.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/crosswalk/ListKCrosswalk.kt new file mode 100644 index 000000000..10e8c6272 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/crosswalk/ListKCrosswalk.kt @@ -0,0 +1,57 @@ +package arrow.core.extensions.list.crosswalk + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.extensions.ListKCrosswalk +import arrow.typeclasses.Align +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("crosswalk") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with crosswalk, crosswalkMap or crosswalkNull from arrow.core.*") +fun crosswalk( + arg0: Align, + arg1: List, + arg2: Function1> +): Kind> = arrow.core.extensions.list.crosswalk.List + .crosswalk() + .crosswalk(arg0, arrow.core.ListK(arg1), arg2) as arrow.Kind> + +@JvmName("sequenceL") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with sequenceValidated or sequenceEither from arrow.core.*") +fun sequenceL(arg0: Align, arg1: List>): Kind> = + arrow.core.extensions.list.crosswalk.List + .crosswalk() + .sequenceL(arg0, arrow.core.ListK(arg1)) as arrow.Kind> + +/** + * cached extension + */ +@PublishedApi() +internal val crosswalk_singleton: ListKCrosswalk = object : arrow.core.extensions.ListKCrosswalk {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Crosswalk typeclasses is deprecated. Use concrete methods on List") + inline fun crosswalk(): ListKCrosswalk = crosswalk_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/eq/ListKEq.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/eq/ListKEq.kt new file mode 100644 index 000000000..5c180e521 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/eq/ListKEq.kt @@ -0,0 +1,42 @@ +package arrow.core.extensions.list.eq + +import arrow.core.extensions.ListKEq +import arrow.typeclasses.Eq +import arrow.core.eqv as _eqv +import arrow.core.neqv as _neqv +import kotlin.Boolean +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("eqv") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("neqv(EQL, EQR, arg1)", "arrow.core.neqv")) +fun List.eqv(EQ: Eq, arg1: List): Boolean = + _eqv(EQ, arg1) + +@JvmName("neqv") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("neqv(EQL, EQR, arg1)", "arrow.core.neqv")) +fun List.neqv(EQ: Eq, arg1: List): Boolean = + _neqv(EQ, arg1) + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("@extension projected functions are deprecated", ReplaceWith("listEq(EQ)", "arrow.core.listEq")) + inline fun eq(EQ: Eq): ListKEq = object : arrow.core.extensions.ListKEq { override + fun EQ(): arrow.typeclasses.Eq = EQ }} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/eqK/ListKEqK.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/eqK/ListKEqK.kt new file mode 100644 index 000000000..f7bf8a5dd --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/eqK/ListKEqK.kt @@ -0,0 +1,51 @@ +package arrow.core.extensions.list.eqK + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.extensions.ListKEqK +import arrow.typeclasses.Eq +import kotlin.Boolean +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("eqK") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +fun List.eqK(arg1: List, arg2: Eq): Boolean = + arrow.core.extensions.list.eqK.List.eqK().run { + arrow.core.ListK(this@eqK).eqK(arrow.core.ListK(arg1), arg2) as kotlin.Boolean +} + +@JvmName("liftEq") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +fun liftEq(arg0: Eq): Eq> = arrow.core.extensions.list.eqK.List + .eqK() + .liftEq(arg0) as arrow.typeclasses.Eq> + +/** + * cached extension + */ +@PublishedApi() +internal val eqK_singleton: ListKEqK = object : arrow.core.extensions.ListKEqK {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") + inline fun eqK(): ListKEqK = eqK_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/foldable/ListKFoldable.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/foldable/ListKFoldable.kt new file mode 100644 index 000000000..e645f45a1 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/foldable/ListKFoldable.kt @@ -0,0 +1,346 @@ +package arrow.core.extensions.list.foldable + +import arrow.Kind +import arrow.core.Eval +import arrow.core.foldRight as _foldRight +import arrow.core.ForListK +import arrow.core.Option +import arrow.core.combineAll as _combineAll +import arrow.core.foldMap as _foldMap +import arrow.core.extensions.ListKFoldable +import arrow.core.reduceOrNull +import arrow.core.reduceRightEvalOrNull +import arrow.typeclasses.Applicative +import arrow.typeclasses.Monad +import arrow.typeclasses.Monoid +import kotlin.collections.all as _all +import kotlin.collections.isNotEmpty as _isNotEmpty +import kotlin.Boolean +import kotlin.Function1 +import kotlin.Function2 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("foldLeft") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("fold(arg1, arg2)")) +fun List.foldLeft(arg1: B, arg2: Function2): B = + fold(arg1, arg2) + +@JvmName("foldRight") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("foldRight(arg1, arg2)", "arrow.core.foldRight")) +fun List.foldRight(arg1: Eval, arg2: Function2, Eval>): Eval = + _foldRight(arg1, arg2) + +@JvmName("fold") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("combineAll(arg1)", "arrow.core.combineAll")) +fun List.fold(arg1: Monoid): A = + _combineAll(arg1) + +@JvmName("reduceLeftToOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(reduceNullable(arg1, arg2))", "arrow.core.reduceNullable", "arrow.core.Option")) +fun List.reduceLeftToOption(arg1: Function1, arg2: Function2): Option = + Option.fromNullable(reduceOrNull(arg1, arg2)) + +@JvmName("reduceRightToOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("reduceRightNullable(arg1, arg2).map { Option.fromNullable(it) }", "arrow.core.reduceRightNullable", "arrow.core.Option")) +fun List.reduceRightToOption(arg1: Function1, arg2: Function2, Eval>): Eval> = + reduceRightEvalOrNull(arg1, arg2).map { Option.fromNullable(it) } + +@JvmName("reduceLeftOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith(" Option.fromNullable(reduceNullable({ it }, arg1))", "arrow.core.reduceNullable", "arrow.core.Option")) +fun List.reduceLeftOption(arg1: Function2): Option = + Option.fromNullable(reduceOrNull({ it }, arg1)) + +@JvmName("reduceRightOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("reduceRightOption({ it }, arg2).map { Option.fromNullable(it) }", "arrow.core.reduceRightNullable", "arrow.core.Option")) +fun List.reduceRightOption(arg1: Function2, Eval>): Eval> = + reduceRightEvalOrNull({ it }, arg1).map { Option.fromNullable(it) } + +@JvmName("combineAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("combineAll(arg1)", "arrow.core.combineAll")) +fun List.combineAll(arg1: Monoid): A = + _combineAll(arg1) + +@JvmName("foldMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("foldMap(arg1, arg2)", "arrow.core.foldMap")) +fun List.foldMap(arg1: Monoid, arg2: Function1): B = + _foldMap(arg1, arg2) + +@JvmName("orEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listOf(arg1.empty())")) +fun orEmpty(arg0: Applicative, arg1: Monoid): List = + listOf(arg1.empty()) + +@JvmName("traverse_") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with traverseValidated_ or traverseEither_ from arrow.core.*") +fun List.traverse_(arg1: Applicative, arg2: Function1>): Kind = + arrow.core.extensions.list.foldable.List.foldable().run { + arrow.core.ListK(this@traverse_).traverse_(arg1, arg2) as arrow.Kind + } + +@JvmName("sequence_") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with sequenceValidated_ or sequenceEither_ from arrow.core.*") +fun List>.sequence_(arg1: Applicative): Kind = + arrow.core.extensions.list.foldable.List.foldable().run { + arrow.core.ListK(this@sequence_).sequence_(arg1) as arrow.Kind + } + +@JvmName("find") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull(arg1))", "arrow.core.Option")) +fun List.find(arg1: Function1): Option = + Option.fromNullable(firstOrNull(arg1)) + +@JvmName("exists") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("any(arg1)")) +fun List.exists(arg1: Function1): Boolean = + any(arg1) + +@JvmName("forAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("all(arg1)")) +fun List.forAll(arg1: Function1): Boolean = + _all(arg1) + +@JvmName("all") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("all(arg1)")) +fun List.all(arg1: Function1): Boolean = + _all(arg1) + +@JvmName("nonEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("isNotEmpty()")) +fun List.nonEmpty(): Boolean = + _isNotEmpty() + +@JvmName("isNotEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("isNotEmpty()")) +fun List.isNotEmpty(): Boolean = + _isNotEmpty() + +@JvmName("foldMapA") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +fun , MO : Monoid> List.foldMapA( + arg1: AP, + arg2: MO, + arg3: Function1> +): Kind = arrow.core.extensions.list.foldable.List.foldable().run { + arrow.core.ListK(this@foldMapA).foldMapA(arg1, arg2, arg3) as arrow.Kind +} + +@JvmName("foldMapM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +fun , MO : Monoid> List.foldMapM( + arg1: MA, + arg2: MO, + arg3: Function1> +): Kind = arrow.core.extensions.list.foldable.List.foldable().run { + arrow.core.ListK(this@foldMapM).foldMapM(arg1, arg2, arg3) as arrow.Kind +} + +@JvmName("foldM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +fun List.foldM( + arg1: Monad, + arg2: B, + arg3: Function2> +): Kind = arrow.core.extensions.list.foldable.List.foldable().run { + arrow.core.ListK(this@foldM).foldM(arg1, arg2, arg3) as arrow.Kind +} + +@JvmName("firstOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull())", "arrow.core.Option")) +fun List.firstOption(): Option = + Option.fromNullable(firstOrNull()) + +@JvmName("firstOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull(arg1))", "arrow.core.Option")) +fun List.firstOption(arg1: Function1): Option = + Option.fromNullable(firstOrNull(arg1)) + +@JvmName("firstOrNone") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull())", "arrow.core.Option")) +fun List.firstOrNone(): Option = + Option.fromNullable(firstOrNull()) + +@JvmName("firstOrNone") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull(arg1))", "arrow.core.Option")) +fun List.firstOrNone(arg1: Function1): Option = + Option.fromNullable(firstOrNull(arg1)) + +@JvmName("toList") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("this")) +fun List.toList(): List = + this + +/** + * cached extension + */ +@PublishedApi() +internal val foldable_singleton: ListKFoldable = object : arrow.core.extensions.ListKFoldable {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Foldable typeclasses is deprecated. Use concrete methods on List") + inline fun foldable(): ListKFoldable = foldable_singleton +} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/functor/ListKFunctor.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/functor/ListKFunctor.kt new file mode 100644 index 000000000..27b7e2f9d --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/functor/ListKFunctor.kt @@ -0,0 +1,194 @@ +package arrow.core.extensions.list.functor + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.void as _void +import arrow.core.fproduct as _fproduct +import arrow.core.mapConst as _mapConst +import arrow.core.tupleLeft as _tupleLeft +import arrow.core.tupleRight as _tupleRight +import arrow.core.widen as _widen +import arrow.core.Tuple2 +import arrow.core.extensions.ListKFunctor +import kotlin.Function1 +import kotlin.collections.map as _map +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +/** + * Transform the [F] wrapped value [A] into [B] preserving the [F] structure + * Kind -> Kind + * + * ```kotlin:ank:playground + * import arrow.core.* + * import arrow.core.extensions.listk.functor.* + * import arrow.core.* + * + * + * import arrow.core.extensions.listk.applicative.just + * + * fun main(args: Array) { + * val result = + * //sampleStart + * "Hello".just().map({ "$it World" }) + * //sampleEnd + * println(result) + * } + * ``` + */ +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("map(arg1)")) +fun List.map(arg1: Function1): List = + _map(arg1) + +@JvmName("imap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("map(arg1)")) +fun List.imap(arg1: Function1, arg2: Function1): List = + _map(arg1) + +/** + * Lifts a function `A -> B` to the [F] structure returning a polymorphic function + * that can be applied over all [F] values in the shape of Kind + * + * `A -> B -> Kind -> Kind` + * + * ```kotlin:ank:playground + * import arrow.core.* + * import arrow.core.extensions.listk.functor.* + * import arrow.core.* + * + * + * import arrow.core.extensions.listk.applicative.just + * + * fun main(args: Array) { + * val result = + * //sampleStart + * lift({ s: CharSequence -> "$s World" })("Hello".just()) + * //sampleEnd + * println(result) + * } + * ``` + */ +@JvmName("lift") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("{ l: List -> l.map(arg0) }")) +fun lift(arg0: Function1): Function1, Kind> = + arrow.core.extensions.list.functor.List + .functor() + .lift(arg0) as kotlin.Function1, + arrow.Kind> + +@JvmName("void") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("void()", "arrow.core.void")) +fun List.void(): List = + _void() + +@JvmName("fproduct") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("fproduct(arg1)", "arrow.core.fproduct")) +fun List.fproduct(arg1: Function1): List> = + _fproduct(arg1) + +@JvmName("mapConst") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapConst(arg1)", "arrow.core.mapConst")) +fun List.mapConst(arg1: B): List = + _mapConst(arg1) + +/** + * Replaces the [B] value inside [F] with [A] resulting in a Kind + */ +@JvmName("mapConst") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg1.mapConst(this)", "arrow.core.mapConst")) +fun A.mapConst(arg1: List): List = + arg1._mapConst(this) + +@JvmName("tupleLeft") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("tupleLeft(arg1)", "arrow.core.tupleLeft")) +fun List.tupleLeft(arg1: B): List> = + _tupleLeft(arg1) + +@JvmName("tupleRight") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("tupleRight(arg1)", "arrow.core.tupleRight")) +fun List.tupleRight(arg1: B): List> = + _tupleRight(arg1) + +@JvmName("widen") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("widen()", "arrow.core.widen")) +fun List.widen(): List = + _widen() + +/** + * cached extension + */ +@PublishedApi() +internal val functor_singleton: ListKFunctor = object : arrow.core.extensions.ListKFunctor {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Functor typeclasses is deprecated. Use concrete methods on List") + inline fun functor(): ListKFunctor = functor_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/functorFilter/ListKFunctorFilter.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/functorFilter/ListKFunctorFilter.kt new file mode 100644 index 000000000..2fa016c3b --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/functorFilter/ListKFunctorFilter.kt @@ -0,0 +1,72 @@ +package arrow.core.extensions.list.functorFilter + +import arrow.core.Option +import arrow.core.extensions.ListKFunctorFilter +import java.lang.Class +import kotlin.Boolean +import kotlin.collections.filter as _filter +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("filterMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapNotNull { arg1(it).orNull() }")) +fun List.filterMap(arg1: Function1>): List = + mapNotNull { arg1(it).orNull() } + +@JvmName("flattenOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapNotNull { it.orNull() }")) +fun List>.flattenOption(): List = + mapNotNull { it.orNull() } + +@JvmName("filter") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("filter(arg1)")) +fun List.filter(arg1: Function1): List = + _filter(arg1) + +@JvmName("filterIsInstance") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("filter(arg1::isInstance).map { arg1.cast(it) }")) +fun List.filterIsInstance(arg1: Class): List = + _filter(arg1::isInstance).map { arg1.cast(it) } + +/** + * cached extension + */ +@PublishedApi() +internal val functorFilter_singleton: ListKFunctorFilter = object : + arrow.core.extensions.ListKFunctorFilter {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Functor typeclasses is deprecated. Use concrete methods on List") + inline fun functorFilter(): ListKFunctorFilter = functorFilter_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/hash/ListKHash.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/hash/ListKHash.kt new file mode 100644 index 000000000..6028596b2 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/hash/ListKHash.kt @@ -0,0 +1,42 @@ +package arrow.core.extensions.list.hash + +import arrow.core.extensions.ListKHash +import arrow.typeclasses.Hash +import arrow.core.hash as _hash +import arrow.core.hashWithSalt as _hashWithSalt +import kotlin.Int +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("hash") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("hash(HA)", "arrow.core.hash")) +fun List.hash(HA: Hash): Int = + _hash(HA) + +@JvmName("hashWithSalt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("hashWithSalt(HA, arg1)", "arrow.core.hashWithSalt")) +fun List.hashWithSalt(HA: Hash, arg1: Int): Int = + _hashWithSalt(HA, arg1) + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("@extension projected functions are deprecated", ReplaceWith("listHash(HA)", "arrow.core.listHash")) + inline fun hash(HA: Hash): ListKHash = object : arrow.core.extensions.ListKHash { + override fun HA(): arrow.typeclasses.Hash = HA }} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monad/ListKMonad.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monad/ListKMonad.kt new file mode 100644 index 000000000..4995b5d88 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monad/ListKMonad.kt @@ -0,0 +1,283 @@ +package arrow.core.extensions.list.monad + +import arrow.Kind +import arrow.core.Either +import arrow.core.Eval +import arrow.core.ForListK +import arrow.core.Tuple2 +import arrow.core.extensions.ListKMonad +import arrow.core.fix +import arrow.core.tailRecMIterable +import kotlin.Boolean +import kotlin.collections.flatMap as _flatMap +import kotlin.Function0 +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("flatMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap(arg1)")) +fun List.flatMap(arg1: Function1>): List = + _flatMap { arg1(it).fix() } + +@JvmName("tailRecM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("tailRecMIterable(arg0) { arg1(it) }")) +fun tailRecM(arg0: A, arg1: Function1>>): List = + tailRecMIterable(arg0) { arg1(it).fix() } + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("map(arg1)")) +fun List.map(arg1: Function1): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@map).map(arg1) as kotlin.collections.List +} + +/** + * @see [Apply.ap] + */ +@JvmName("ap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("ap(arg1)", "arrow.core.ap")) +fun List.ap(arg1: List>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@ap).ap(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@JvmName("flatten") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatten")) +fun List>.flatten(): List = arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@flatten).flatten() as kotlin.collections.List +} + +@JvmName("followedBy") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { arg1 }")) +fun List.followedBy(arg1: List): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@followedBy).followedBy(arrow.core.ListK(arg1)) as + kotlin.collections.List +} + +@JvmName("apTap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.map { a } }")) +fun List.apTap(arg1: List): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@apTap).apTap(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@JvmName("followedByEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { arg1.value() }")) +fun List.followedByEval(arg1: Eval>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@followedByEval).followedByEval(arg1) as kotlin.collections.List +} + +@JvmName("effectM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1(a).map { a } }")) +fun List.effectM(arg1: Function1>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@effectM).effectM(arg1) as kotlin.collections.List +} + +@JvmName("flatTap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1(a).map { a } }")) +fun List.flatTap(arg1: Function1>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@flatTap).flatTap(arg1) as kotlin.collections.List +} + +@JvmName("productL") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.map { a } }")) +fun List.productL(arg1: List): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@productL).productL(arrow.core.ListK(arg1)) as + kotlin.collections.List +} + +@JvmName("forEffect") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.map { a } }")) +fun List.forEffect(arg1: List): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@forEffect).forEffect(arrow.core.ListK(arg1)) as + kotlin.collections.List +} + +@JvmName("productLEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.value().map { a } }")) +fun List.productLEval(arg1: Eval>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@productLEval).productLEval(arg1) as kotlin.collections.List +} + +@JvmName("forEffectEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.value().map { a } }")) +fun List.forEffectEval(arg1: Eval>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@forEffectEval).forEffectEval(arg1) as kotlin.collections.List +} + +@JvmName("mproduct") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1(a).map { b -> Tuple2(a, b) } }")) +fun List.mproduct(arg1: Function1>): List> = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@mproduct).mproduct(arg1) as + kotlin.collections.List> +} + +@JvmName("ifM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("ifM(arg1, arg2)", "arrow.core.ifM")) +fun List.ifM(arg1: Function0>, arg2: Function0>): + List = arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@ifM).ifM(arg1, arg2) as kotlin.collections.List +} + +@JvmName("selectM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("selectM(arg1)", "arrow.core.selectM")) +fun List>.selectM(arg1: List>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@selectM).selectM(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@JvmName("select") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("select(arg1)", "arrow.core.select")) +fun List>.select(arg1: List>): List = + arrow.core.extensions.list.monad.List.monad().run { + arrow.core.ListK(this@select).select(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +/** + * cached extension + */ +@PublishedApi() +internal val monad_singleton: ListKMonad = object : arrow.core.extensions.ListKMonad {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + /** + * ank_macro_hierarchy(arrow.typeclasses.Monad) + * + * [Monad] abstract over the ability to declare sequential computations that are dependent in the order or + * the results of previous computations. + * + * Given a type constructor [F] with a value of [A] we can compose multiple operations of type + * `Kind` where `?` denotes a value being transformed. + * + * This is true for all type constructors that can support the [Monad] type class including and not limited to + * [IO], [ObservableK], [Option], [Either], [List] ... + * + * [The Monad Tutorial](https://arrow-kt.io/docs/patterns/monads/) + */ + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Monad typeclasses are deprecated. Use concrete methods on List") + inline fun monad(): ListKMonad = monad_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadCombine/ListKMonadCombine.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadCombine/ListKMonadCombine.kt new file mode 100644 index 000000000..acc017c96 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadCombine/ListKMonadCombine.kt @@ -0,0 +1,55 @@ +package arrow.core.extensions.list.monadCombine + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.Tuple2 +import arrow.core.extensions.ListKMonadCombine +import arrow.typeclasses.Bifoldable +import arrow.typeclasses.Foldable +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("unite") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Foldable typeclasses is deprecated. Use concrete methods on List") +fun List>.unite(arg1: Foldable): List = + arrow.core.extensions.list.monadCombine.List.monadCombine().run { + arrow.core.ListK(this@unite).unite(arg1) as kotlin.collections.List +} + +@JvmName("separate") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Foldable typeclasses is deprecated. Use concrete methods on List") +fun List, B>>.separate(arg1: Bifoldable): Tuple2, + Kind> = arrow.core.extensions.list.monadCombine.List.monadCombine().run { + arrow.core.ListK(this@separate).separate(arg1) as + arrow.core.Tuple2, arrow.Kind> +} + +/** + * cached extension + */ +@PublishedApi() +internal val monadCombine_singleton: ListKMonadCombine = object : + arrow.core.extensions.ListKMonadCombine {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("MonadCombine typeclasses is deprecated. Use concrete methods on List") + inline fun monadCombine(): ListKMonadCombine = monadCombine_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadFilter/ListKMonadFilter.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadFilter/ListKMonadFilter.kt new file mode 100644 index 000000000..0452770a6 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadFilter/ListKMonadFilter.kt @@ -0,0 +1,53 @@ +package arrow.core.extensions.list.monadFilter + +import arrow.core.ForListK +import arrow.core.Option +import arrow.core.extensions.ListKMonadFilter +import arrow.typeclasses.MonadFilterSyntax +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("filterMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapNotNull { arg1(it).orNull() }")) +fun List.filterMap(arg1: Function1>): List = + arrow.core.extensions.list.monadFilter.List.monadFilter().run { + arrow.core.ListK(this@filterMap).filterMap(arg1) as kotlin.collections.List +} + +@JvmName("bindingFilter") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Monad bindings are deprecated") +fun bindingFilter(arg0: suspend MonadFilterSyntax.() -> B): List = + arrow.core.extensions.list.monadFilter.List + .monadFilter() + .bindingFilter(arg0) as kotlin.collections.List + +/** + * cached extension + */ +@PublishedApi() +internal val monadFilter_singleton: ListKMonadFilter = object : + arrow.core.extensions.ListKMonadFilter {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("MonadFilter typeclasses is deprecated. Use concrete methods on List") + inline fun monadFilter(): ListKMonadFilter = monadFilter_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadLogic/ListKMonadLogic.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadLogic/ListKMonadLogic.kt new file mode 100644 index 000000000..3f20ac096 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadLogic/ListKMonadLogic.kt @@ -0,0 +1,110 @@ +package arrow.core.extensions.list.monadLogic + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.Option +import arrow.core.Tuple2 +import arrow.core.extensions.ListKMonadLogic +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("splitM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("split()", "arrow.core.split")) +fun List.splitM(): List, A>>> = + arrow.core.extensions.list.monadLogic.List.monadLogic().run { + arrow.core.ListK(this@splitM).splitM() as + kotlin.collections.List, + A>>> +} + +@JvmName("interleave") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("interleave(arg1)", "arrow.core.interleave")) +fun List.interleave(arg1: List): List = + arrow.core.extensions.list.monadLogic.List.monadLogic().run { + arrow.core.ListK(this@interleave).interleave(arrow.core.ListK(arg1)) as + kotlin.collections.List +} + +@JvmName("unweave") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("unweave(arg1)", "arrow.core.unweave")) +fun List.unweave(arg1: Function1>): List = + arrow.core.extensions.list.monadLogic.List.monadLogic().run { + arrow.core.ListK(this@unweave).unweave(arg1) as kotlin.collections.List +} + +@JvmName("ifThen") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("ifThen(arg1, arg2)", "arrow.core.ifThen")) +fun List.ifThen(arg1: List, arg2: Function1>): List = + arrow.core.extensions.list.monadLogic.List.monadLogic().run { + arrow.core.ListK(this@ifThen).ifThen(arrow.core.ListK(arg1), arg2) as + kotlin.collections.List +} + +@JvmName("once") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listOfNotNull(firstOrNull())")) +fun List.once(): List = arrow.core.extensions.list.monadLogic.List.monadLogic().run { + arrow.core.ListK(this@once).once() as kotlin.collections.List +} + +@JvmName("voidIfValue") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("firstOrNull()?.let { emptyList() } ?: listOf(Unit)")) +fun List.voidIfValue(): List = + arrow.core.extensions.list.monadLogic.List.monadLogic().run { + arrow.core.ListK(this@voidIfValue).voidIfValue() as kotlin.collections.List +} + +/** + * cached extension + */ +@PublishedApi() +internal val monadLogic_singleton: ListKMonadLogic = object : arrow.core.extensions.ListKMonadLogic + {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("MonadLogic typeclasses is deprecated. Use concrete methods on List") + inline fun monadLogic(): ListKMonadLogic = monadLogic_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadPlus/ListKMonadPlus.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadPlus/ListKMonadPlus.kt new file mode 100644 index 000000000..ee22adfcf --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monadPlus/ListKMonadPlus.kt @@ -0,0 +1,47 @@ +package arrow.core.extensions.list.monadPlus + +import arrow.core.extensions.ListKMonadPlus +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("zeroM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("emptyList()")) +fun zeroM(): List = arrow.core.extensions.list.monadPlus.List + .monadPlus() + .zeroM() as kotlin.collections.List + +@JvmName("plusM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("this + arg1")) +fun List.plusM(arg1: List): List = + arrow.core.extensions.list.monadPlus.List.monadPlus().run { + arrow.core.ListK(this@plusM).plusM(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +/** + * cached extension + */ +@PublishedApi() +internal val monadPlus_singleton: ListKMonadPlus = object : arrow.core.extensions.ListKMonadPlus {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("MonadPlus typeclasses is deprecated. Use concrete methods on List") + inline fun monadPlus(): ListKMonadPlus = monadPlus_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoid/ListKMonoid.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoid/ListKMonoid.kt new file mode 100644 index 000000000..f3170be0f --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoid/ListKMonoid.kt @@ -0,0 +1,50 @@ +package arrow.core.extensions.list.monoid + +import arrow.core.ListK +import arrow.core.extensions.ListKMonoid +import kotlin.Any +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.Collection +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("combineAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.fold(emptyList()) { acc, l -> acc + l }")) +fun Collection>.combineAll(): List = + arrow.core.extensions.list.monoid.List.monoid().run { + this@combineAll.combineAll() as kotlin.collections.List +} + +@JvmName("combineAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.fold(emptyList()) { acc, l -> acc + l }")) +fun combineAll(arg0: List>): List = + arg0.fold(emptyList()) { acc, l -> acc + l } + +/** + * cached extension + */ +@PublishedApi() +internal val monoid_singleton: ListKMonoid = object : ListKMonoid {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) + inline fun monoid(): ListKMonoid = monoid_singleton as + arrow.core.extensions.ListKMonoid} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoidK/ListKMonoidK.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoidK/ListKMonoidK.kt new file mode 100644 index 000000000..d710cdbc1 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoidK/ListKMonoidK.kt @@ -0,0 +1,36 @@ +package arrow.core.extensions.list.monoidK + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.extensions.ListKMonoidK +import arrow.typeclasses.Monoid +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +@JvmName("algebra") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) +fun algebra(): Monoid> = arrow.core.extensions.list.monoidK.List + .monoidK() + .algebra() as arrow.typeclasses.Monoid> + +/** + * cached extension + */ +@PublishedApi() +internal val monoidK_singleton: ListKMonoidK = object : arrow.core.extensions.ListKMonoidK {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") + inline fun monoidK(): ListKMonoidK = monoidK_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoidal/ListKMonoidal.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoidal/ListKMonoidal.kt new file mode 100644 index 000000000..44dcb37a2 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/monoidal/ListKMonoidal.kt @@ -0,0 +1,34 @@ +package arrow.core.extensions.list.monoidal + +import arrow.core.extensions.ListKMonoidal +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("identity") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("emptyList()")) +fun identity(): List = arrow.core.extensions.list.monoidal.List + .monoidal() + .identity() as kotlin.collections.List + +/** + * cached extension + */ +@PublishedApi() +internal val monoidal_singleton: ListKMonoidal = object : arrow.core.extensions.ListKMonoidal {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Monoidal typeclasses is deprecated. Use concrete methods on List") + inline fun monoidal(): ListKMonoidal = monoidal_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/order/ListKOrder.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/order/ListKOrder.kt new file mode 100644 index 000000000..e5acd8661 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/order/ListKOrder.kt @@ -0,0 +1,137 @@ +package arrow.core.extensions.list.order + +import arrow.core.Ordering +import arrow.core.extensions.ListKOrder +import arrow.typeclasses.Order +import kotlin.Boolean +import kotlin.Int +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("compare") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("compare(OA, arg1)", "arrow.core.compare")) +fun List.compare(OA: Order, arg1: List): Ordering = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@compare).compare(arrow.core.ListK(arg1)) as arrow.core.Ordering +} + +@JvmName("compareTo") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("compareTo(OA, arg1)", "arrow.core.compareTo")) +fun List.compareTo(OA: Order, arg1: List): Int = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@compareTo).compareTo(arrow.core.ListK(arg1)) as kotlin.Int +} + +@JvmName("eqv") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("eqv(OA, arg1)", "arrow.core.eqv")) +fun List.eqv(OA: Order, arg1: List): Boolean = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@eqv).eqv(arrow.core.ListK(arg1)) as kotlin.Boolean +} + +@JvmName("lt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("lt(OA, arg1)", "arrow.core.lt")) +fun List.lt(OA: Order, arg1: List): Boolean = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@lt).lt(arrow.core.ListK(arg1)) as kotlin.Boolean +} + +@JvmName("lte") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("lte(OA, arg1)", "arrow.core.lte")) +fun List.lte(OA: Order, arg1: List): Boolean = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@lte).lte(arrow.core.ListK(arg1)) as kotlin.Boolean +} + +@JvmName("gt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("gt(OA, arg1)", "arrow.core.gt")) +fun List.gt(OA: Order, arg1: List): Boolean = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@gt).gt(arrow.core.ListK(arg1)) as kotlin.Boolean +} + +@JvmName("gte") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("gte(OA, arg1)", "arrow.core.gte")) +fun List.gte(OA: Order, arg1: List): Boolean = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@gte).gte(arrow.core.ListK(arg1)) as kotlin.Boolean +} + +@JvmName("max") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("max(OA, arg1)", "arrow.core.max")) +fun List.max(OA: Order, arg1: List): List = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@max).max(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@JvmName("min") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("min(OA, arg1)", "arrow.core.min")) +fun List.min(OA: Order, arg1: List): List = + arrow.core.extensions.list.order.List.order(OA).run { + arrow.core.ListK(this@min).min(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("@extension projected functions are deprecated", ReplaceWith("listOrder(OA)", "arrow.core.listOrder")) + inline fun order(OA: Order): ListKOrder = object : arrow.core.extensions.ListKOrder { + override fun OA(): arrow.typeclasses.Order = OA }} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/semialign/ListKSemialign.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semialign/ListKSemialign.kt new file mode 100644 index 000000000..cb9e48c9b --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semialign/ListKSemialign.kt @@ -0,0 +1,101 @@ +package arrow.core.extensions.list.semialign + +import arrow.core.Ior +import arrow.core.Option +import arrow.core.Tuple2 +import arrow.core.extensions.ListKSemialign +import arrow.typeclasses.Semigroup +import kotlin.Function1 +import kotlin.Function2 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("align") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.align(arg1)", "arrow.core.align")) +fun align(arg0: List, arg1: List): List> = + arrow.core.extensions.list.semialign.List + .semialign() + .align(arrow.core.ListK(arg0), arrow.core.ListK(arg1)) as + kotlin.collections.List> + +@JvmName("alignWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.align(arg1, arg2)", "arrow.core.align")) +fun alignWith( + arg0: List, + arg1: List, + arg2: Function1, C> +): List = arrow.core.extensions.list.semialign.List + .semialign() + .alignWith(arrow.core.ListK(arg0), arrow.core.ListK(arg1), arg2) as + kotlin.collections.List + +@JvmName("salign") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.salign(arg1, arg2)", "arrow.core.salign")) +fun List.salign(arg1: Semigroup, arg2: List): List = + arrow.core.extensions.list.semialign.List.semialign().run { + arrow.core.ListK(this@salign).salign(arg1, arrow.core.ListK(arg2)) as + kotlin.collections.List +} + +@JvmName("padZip") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.padZip(arg1)", "arrow.core.padZip")) +fun List.padZip(arg1: List): List, Option>> = + arrow.core.extensions.list.semialign.List.semialign().run { + arrow.core.ListK(this@padZip).padZip(arrow.core.ListK(arg1)) as + kotlin.collections.List, arrow.core.Option>> +} + +@JvmName("padZipWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.padZip(arg1, arg2)", "arrow.core.padZip")) +fun List.padZipWith(arg1: List, arg2: Function2, Option, C>): List = + arrow.core.extensions.list.semialign.List.semialign().run { + arrow.core.ListK(this@padZipWith).padZipWith(arrow.core.ListK(arg1), arg2) as + kotlin.collections.List +} + +/** + * cached extension + */ +@PublishedApi() +internal val semialign_singleton: ListKSemialign = object : arrow.core.extensions.ListKSemialign {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Semialign typeclasses is deprecated. Use concrete methods on List") + inline fun semialign(): ListKSemialign = semialign_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroup/ListKSemigroup.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroup/ListKSemigroup.kt new file mode 100644 index 000000000..023b199fc --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroup/ListKSemigroup.kt @@ -0,0 +1,51 @@ +package arrow.core.extensions.list.semigroup + +import arrow.core.extensions.ListKSemigroup +import kotlin.Any +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("plus") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("this.plus(arg1)")) +operator fun List.plus(arg1: List): List = + arrow.core.extensions.list.semigroup.List.semigroup().run { + arrow.core.ListK(this@plus).plus(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@JvmName("maybeCombine") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("(arg1?.plus(this) ?: emptyList())")) +fun List.maybeCombine(arg1: List): List = + arrow.core.extensions.list.semigroup.List.semigroup().run { + arrow.core.ListK(this@maybeCombine).maybeCombine(arrow.core.ListK(arg1)) as + kotlin.collections.List +} + +/** + * cached extension + */ +@PublishedApi() +internal val semigroup_singleton: ListKSemigroup = object : ListKSemigroup {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) + inline fun semigroup(): ListKSemigroup = semigroup_singleton as + arrow.core.extensions.ListKSemigroup} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroupK/ListKSemigroupK.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroupK/ListKSemigroupK.kt new file mode 100644 index 000000000..3708ca3dc --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroupK/ListKSemigroupK.kt @@ -0,0 +1,51 @@ +package arrow.core.extensions.list.semigroupK + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.extensions.ListKSemigroupK +import arrow.typeclasses.Semigroup +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("combineK") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List.combineK(arg1: List): List = + arrow.core.extensions.list.semigroupK.List.semigroupK().run { + arrow.core.ListK(this@combineK).combineK(arrow.core.ListK(arg1)) as kotlin.collections.List +} + +@JvmName("algebra") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) +fun algebra(): Semigroup> = arrow.core.extensions.list.semigroupK.List + .semigroupK() + .algebra() as arrow.typeclasses.Semigroup> + +/** + * cached extension + */ +@PublishedApi() +internal val semigroupK_singleton: ListKSemigroupK = object : arrow.core.extensions.ListKSemigroupK + {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") + inline fun semigroupK(): ListKSemigroupK = semigroupK_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroupal/ListKSemigroupal.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroupal/ListKSemigroupal.kt new file mode 100644 index 000000000..f8d389510 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/semigroupal/ListKSemigroupal.kt @@ -0,0 +1,144 @@ +package arrow.core.extensions.list.semigroupal + +import arrow.core.Tuple2 +import arrow.core.extensions.ListKSemigroupal +import arrow.core.product as _product +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +/** + * Multiplicatively combine F and F into F> + */ +@JvmName("product") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun List.product(arg1: List): List> = + _product(arg1) + +/** + * syntax + */ +@JvmName("times") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +operator fun List.times(arg1: List): List> = + _product(arg1) + +/** + * cached extension + */ +@PublishedApi() +internal val semigroupal_singleton: ListKSemigroupal = object : + arrow.core.extensions.ListKSemigroupal {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + /** + * ank_macro_hierarchy(arrow.typeclasses.Semigroupal) + * + * The [Semigroupal] type class for a given type `F` can be seen as an abstraction over the [cartesian product](https://en.wikipedia.org/wiki/Cartesian_product). + * It defines the function [product]. + * + * The [product] function for a given type `F`, `A` and `B` combines a `Kind` and a `Kind` into a `Kind>`. + * This function guarantees compliance with the following laws: + * + * [Semigroupal]s are associative under the bijection `f = (a,(b,c)) -> ((a,b),c)` or `f = ((a,b),c) -> (a,(b,c))`. + * Therefore, the following laws also apply: + * + * ```kotlin + * f((a.product(b)).product(c)) == a.product(b.product(c)) + * ``` + * + * ```kotlin + * f(a.product(b.product(c))) == (a.product(b)).product(c) + * ``` + * + * Currently, [Semigroupal] instances are defined for [Option], [ListK], [SequenceK] and [SetK]. + * + * ```kotlin:ank:playground + * import arrow.core.* + * import arrow.core.extensions.listk.semigroupal.* + * import arrow.core.* + * + * + * + * fun main(args: Array) { + * val result = + * //sampleStart + * ListK.semigroupal() + * //sampleEnd + * println(result) + * } + * ``` + * + * ### Examples + * + * Here a some examples: + * + * ```kotlin:ank:playground + * import arrow.core.Option + * import arrow.core.extensions.option.semigroupal.semigroupal + * + * fun main(args: Array) { + * val result = + * //sampleStart + * Option.semigroupal().run { + * Option.just(1).product(Option.just(1)) + * } + * //sampleEnd + * println(result) + * } + * ``` + * + * [Semigroupal] also has support of the `*` syntax: + * + * ```kotlin:ank:playground + * import arrow.core.Option + * import arrow.core.extensions.option.semigroupal.semigroupal + * + * fun main(args: Array) { + * val result = + * //sampleStart + * Option.semigroupal().run { + * Option.just(2) + * } + * //sampleEnd + * println(result) + * } + * ``` + * The same applies to [ListK], [SequenceK] and [SetK] instances: + * + * ```kotlin:ank:playground + * import arrow.core.ListK + * import arrow.core.extensions.listk.semigroupal.semigroupal + * import arrow.core.k + * + * fun main(args: Array) { + * val result = + * //sampleStart + * ListK.semigroupal().run { + * listOf('a','b','c').k() + * } + * //sampleEnd + * println(result) + * } + * ``` + */ + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") + inline fun semigroupal(): ListKSemigroupal = semigroupal_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/show/ListKShow.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/show/ListKShow.kt new file mode 100644 index 000000000..2a93abd85 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/show/ListKShow.kt @@ -0,0 +1,30 @@ +package arrow.core.extensions.list.show + +import arrow.core.extensions.ListKShow +import arrow.core.show as _show +import arrow.typeclasses.Show +import kotlin.String +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("show") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("show(arg1)", "arrow.core.show")) +fun List.show(SA: Show): String = + _show(SA) + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("@extension projected functions are deprecated", ReplaceWith("listShow(arg1)", "arrow.core.listShow")) + inline fun show(SA: Show): ListKShow = object : arrow.core.extensions.ListKShow { + override fun SA(): arrow.typeclasses.Show = SA }} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/traverse/ListKTraverse.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/traverse/ListKTraverse.kt new file mode 100644 index 000000000..a52a7298e --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/traverse/ListKTraverse.kt @@ -0,0 +1,85 @@ +package arrow.core.extensions.list.traverse + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.extensions.ListKTraverse +import arrow.typeclasses.Applicative +import arrow.typeclasses.Monad +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("traverse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with traverseEither or traverseValidated from arrow.core.*") +fun List.traverse(arg1: Applicative, arg2: Function1>): Kind> = arrow.core.extensions.list.traverse.List.traverse().run { + arrow.core.ListK(this@traverse).traverse(arg1, arg2) as arrow.Kind> +} + +@JvmName("sequence") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with sequenceEither or sequenceValidated from arrow.core.*") +fun List>.sequence(arg1: Applicative): Kind> = + arrow.core.extensions.list.traverse.List.traverse().run { + arrow.core.ListK(this@sequence).sequence(arg1) as arrow.Kind> +} + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map(arg1)")) +fun List.map(arg1: Function1): List = + arrow.core.extensions.list.traverse.List.traverse().run { + arrow.core.ListK(this@map).map(arg1) as kotlin.collections.List +} + +@JvmName("flatTraverse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with flatTraverseEither or flatTraverseValidated from arrow.core.*") +fun List.flatTraverse( + arg1: Monad, + arg2: Applicative, + arg3: Function1>> +): Kind> = arrow.core.extensions.list.traverse.List.traverse().run { + arrow.core.ListK(this@flatTraverse).flatTraverse(arg1, arg2, arg3) as arrow.Kind> +} + +/** + * cached extension + */ +@PublishedApi() +internal val traverse_singleton: ListKTraverse = object : arrow.core.extensions.ListKTraverse {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Traverse typeclasses is deprecated. Use concrete methods on Iterable") + inline fun traverse(): ListKTraverse = traverse_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/unalign/ListKUnalign.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/unalign/ListKUnalign.kt new file mode 100644 index 000000000..dcde8cb3f --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/unalign/ListKUnalign.kt @@ -0,0 +1,55 @@ +package arrow.core.extensions.list.unalign + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.Ior +import arrow.core.Tuple2 +import arrow.core.extensions.ListKUnalign +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("unalign") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.unalign()", "arrow.core.unalign")) +fun unalign(arg0: List>): Tuple2, Kind> = + arrow.core.extensions.list.unalign.List + .unalign() + .unalign(arrow.core.ListK(arg0)) as arrow.core.Tuple2, + arrow.Kind> + +@JvmName("unalignWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.unalign(arg1)", "arrow.core.unalign")) +fun unalignWith(arg0: List, arg1: Function1>): Tuple2, + Kind> = arrow.core.extensions.list.unalign.List + .unalign() + .unalignWith(arrow.core.ListK(arg0), arg1) as + arrow.core.Tuple2, arrow.Kind> + +/** + * cached extension + */ +@PublishedApi() +internal val unalign_singleton: ListKUnalign = object : arrow.core.extensions.ListKUnalign {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Unalign typeclasses is deprecated. Use concrete methods on Iterable") + inline fun unalign(): ListKUnalign = unalign_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/unzip/ListKUnzip.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/unzip/ListKUnzip.kt new file mode 100644 index 000000000..0aadb463d --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/unzip/ListKUnzip.kt @@ -0,0 +1,54 @@ +package arrow.core.extensions.list.unzip + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.Tuple2 +import arrow.core.extensions.ListKUnzip +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.jvm.JvmName + +@JvmName("unzip") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("unzip()", "arrow.core.unzip")) +fun List>.unzip(): Tuple2, Kind> = + arrow.core.extensions.list.unzip.List.unzip().run { + arrow.core.ListK(this@unzip).unzip() as arrow.core.Tuple2, arrow.Kind> +} + +@JvmName("unzipWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("unzip(arg1)", "arrow.core.unzip")) +fun List.unzipWith(arg1: Function1>): Tuple2, + Kind> = arrow.core.extensions.list.unzip.List.unzip().run { + arrow.core.ListK(this@unzipWith).unzipWith(arg1) as + arrow.core.Tuple2, arrow.Kind> +} + +/** + * cached extension + */ +@PublishedApi() +internal val unzip_singleton: ListKUnzip = object : arrow.core.extensions.ListKUnzip {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Unzip typeclasses is deprecated. Use concrete methods on Iterable") + inline fun unzip(): ListKUnzip = unzip_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/list/zip/ListKZip.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/list/zip/ListKZip.kt new file mode 100644 index 000000000..fa681cabb --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/list/zip/ListKZip.kt @@ -0,0 +1,48 @@ +package arrow.core.extensions.list.zip + +import arrow.core.Tuple2 +import arrow.core.extensions.ListKZip +import arrow.core.toTuple2 +import kotlin.Function2 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.List +import kotlin.collections.zip as _zip +import kotlin.jvm.JvmName + +@JvmName("zip") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("zip(arg1).map { it.toTuple2() }", "arrow.core.toTuple2")) +fun List.zip(arg1: List): List> = + _zip(arg1).map { it.toTuple2() } + +@JvmName("zipWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("zip(arg1, arg2)")) +fun List.zipWith(arg1: List, arg2: Function2): List = + _zip(arg1, arg2) + +/** + * cached extension + */ +@PublishedApi() +internal val zip_singleton: ListKZip = object : arrow.core.extensions.ListKZip {} + +@Deprecated("Receiver List object is deprecated, prefer to turn List functions into top-level functions") +object List { + @Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" + ) + @Deprecated("Zip typeclasses is deprecated. Use concrete methods on Iterable") + inline fun zip(): ListKZip = zip_singleton} diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk.kt index e12a8b0f1..930f933e0 100644 --- a/arrow-core/src/main/kotlin/arrow/core/extensions/listk.kt +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk.kt @@ -22,7 +22,6 @@ import arrow.core.fix import arrow.core.identity import arrow.core.k import arrow.core.toT -import arrow.extension import arrow.typeclasses.Align import arrow.typeclasses.Alternative import arrow.typeclasses.Applicative @@ -58,19 +57,16 @@ import arrow.core.combineK as listCombineK import kotlin.collections.plus as listPlus import kotlin.collections.zip as listZip -@extension interface ListKSemigroup : Semigroup> { override fun ListK.combine(b: ListK): ListK = (this.listPlus(b)).k() } -@extension interface ListKMonoid : Monoid>, ListKSemigroup { override fun empty(): ListK = emptyList().k() } -@extension interface ListKEq : Eq> { fun EQ(): Eq @@ -84,19 +80,16 @@ interface ListKEq : Eq> { else false } -@extension interface ListKShow : Show> { fun SA(): Show override fun ListKOf.show(): String = fix().show(SA()) } -@extension interface ListKFunctor : Functor { override fun Kind.map(f: (A) -> B): ListK = fix().map(f) } -@extension interface ListKApply : Apply { override fun Kind.ap(ff: Kind B>): ListK = fix().ap(ff) @@ -108,7 +101,6 @@ interface ListKApply : Apply { fix().map2(fb, f) } -@extension interface ListKApplicative : Applicative { override fun Kind.ap(ff: Kind B>): ListK = fix().ap(ff) @@ -123,7 +115,6 @@ interface ListKApplicative : Applicative { ListK.just(a) } -@extension interface ListKMonad : Monad { override fun Kind.ap(ff: Kind B>): ListK = fix().ap(ff) @@ -150,7 +141,6 @@ interface ListKMonad : Monad { ListK.just(a) } -@extension interface ListKFoldable : Foldable { override fun Kind.foldLeft(b: B, f: (B, A) -> B): B = fix().foldLeft(b, f) @@ -162,7 +152,6 @@ interface ListKFoldable : Foldable { fix().isEmpty() } -@extension interface ListKTraverse : Traverse { override fun Kind.map(f: (A) -> B): ListK = fix().map(f) @@ -180,24 +169,20 @@ interface ListKTraverse : Traverse { fix().isEmpty() } -@extension interface ListKSemigroupK : SemigroupK { override fun Kind.combineK(y: Kind): ListK = fix().listCombineK(y) } -@extension interface ListKSemigroupal : Semigroupal { override fun Kind.product(fb: Kind): Kind> = fb.fix().ap(fix().map { a: A -> { b: B -> Tuple2(a, b) } }) } -@extension interface ListKMonoidal : Monoidal, ListKSemigroupal { override fun identity(): Kind = ListK.empty() } -@extension interface ListKMonoidK : MonoidK { override fun empty(): ListK = ListK.empty() @@ -206,7 +191,6 @@ interface ListKMonoidK : MonoidK { fix().listCombineK(y) } -@extension interface ListKHash : Hash> { fun HA(): Hash @@ -215,7 +199,6 @@ interface ListKHash : Hash> { HA().run { foldLeft(salt) { hash, x -> x.hashWithSalt(hash) } }.hashWithSalt(fix().size) } -@extension interface ListKOrder : Order> { fun OA(): Order override fun ListKOf.compare(b: ListKOf): Ordering = @@ -223,7 +206,6 @@ interface ListKOrder : Order> { .fold(Ordering.monoid()) } -@extension interface ListKFunctorFilter : FunctorFilter { override fun Kind.filterMap(f: (A) -> Option): ListK = fix().filterMap(f) @@ -235,7 +217,6 @@ interface ListKFunctorFilter : FunctorFilter { fun ListK.Companion.fx(c: suspend MonadSyntax.() -> A): ListK = ListK.monad().fx.monad(c).fix() -@extension interface ListKMonadCombine : MonadCombine, ListKAlternative { override fun empty(): ListK = ListK.empty() @@ -262,7 +243,6 @@ interface ListKMonadCombine : MonadCombine, ListKAlternative { ListK.just(a) } -@extension interface ListKMonadFilter : MonadFilter { override fun empty(): ListK = ListK.empty() @@ -289,14 +269,12 @@ interface ListKMonadFilter : MonadFilter { ListK.just(a) } -@extension interface ListKAlternative : Alternative, ListKApplicative { override fun empty(): Kind = emptyList().k() override fun Kind.orElse(b: Kind): Kind = (this.fix() + b.fix()).k() } -@extension interface ListKEqK : EqK { override fun Kind.eqK(other: Kind, EQ: Eq) = (this.fix() to other.fix()).let { @@ -306,7 +284,6 @@ interface ListKEqK : EqK { } } -@extension interface ListKSemialign : Semialign, ListKFunctor { override fun align( a: Kind, @@ -314,12 +291,10 @@ interface ListKSemialign : Semialign, ListKFunctor { ): Kind> = ListK.align(a.fix(), b.fix()) } -@extension interface ListKAlign : Align, ListKSemialign { override fun empty(): Kind = ListK.empty() } -@extension interface ListKUnalign : Unalign, ListKSemialign { override fun unalign(ior: Kind>): Tuple2, Kind> = ior.fix().let { list -> @@ -333,13 +308,11 @@ interface ListKUnalign : Unalign, ListKSemialign { } } -@extension interface ListKZip : Zip, ListKSemialign { override fun Kind.zip(other: Kind): Kind> = this.fix().listZip(other.fix()).map { it.first toT it.second }.k() } -@extension interface ListKUnzip : Unzip, ListKZip { override fun Kind>.unzip(): Tuple2, Kind> = this.fix().let { list -> @@ -349,7 +322,6 @@ interface ListKUnzip : Unzip, ListKZip { }.bimap({ it.k() }, { it.k() }) } -@extension interface ListKCrosswalk : Crosswalk, ListKFunctor, ListKFoldable { override fun crosswalk( ALIGN: Align, @@ -368,7 +340,6 @@ interface ListKCrosswalk : Crosswalk, ListKFunctor, ListKFoldable { } } -@extension interface ListKMonadPlus : MonadPlus, ListKMonad, ListKAlternative { override fun Kind.ap(ff: Kind B>): ListK = fix().ap(ff) @@ -383,7 +354,6 @@ interface ListKMonadPlus : MonadPlus, ListKMonad, ListKAlternative { ListK.just(a) } -@extension interface ListKMonadLogic : MonadLogic, ListKMonadPlus { private fun ListK.tail(): ListK = this.drop(1).k() diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/align/ListKAlign.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/align/ListKAlign.kt new file mode 100644 index 000000000..109021c7d --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/align/ListKAlign.kt @@ -0,0 +1,33 @@ +package arrow.core.extensions.listk.align + +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKAlign +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val align_singleton: ListKAlign = object : arrow.core.extensions.ListKAlign {} + +@JvmName("empty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("emptyList()")) +fun empty(): ListK = arrow.core.ListK + .align() + .empty() as arrow.core.ListK + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Align typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.align(): ListKAlign = align_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/alternative/ListKAlternative.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/alternative/ListKAlternative.kt new file mode 100644 index 000000000..227a64755 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/alternative/ListKAlternative.kt @@ -0,0 +1,129 @@ +package arrow.core.extensions.listk.alternative + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Option +import arrow.core.SequenceK +import arrow.core.extensions.ListKAlternative +import kotlin.Boolean +import kotlin.Function0 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val alternative_singleton: ListKAlternative = object : + arrow.core.extensions.ListKAlternative {} + +@JvmName("some") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("This method results in StackOverflow") +fun Kind.some(): ListK> = arrow.core.ListK.alternative().run { + this@some.some() as arrow.core.ListK> +} + +@JvmName("many") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("This method results in StackOverflow") +fun Kind.many(): ListK> = arrow.core.ListK.alternative().run { + this@many.many() as arrow.core.ListK> +} + +@JvmName("alt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1")) +infix fun Kind.alt(arg1: Kind): ListK = + arrow.core.ListK.alternative().run { + this@alt.alt(arg1) as arrow.core.ListK +} + +@JvmName("orElse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1")) +fun Kind.orElse(arg1: Kind): ListK = + arrow.core.ListK.alternative().run { + this@orElse.orElse(arg1) as arrow.core.ListK +} + +@JvmName("combineK") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1")) +fun Kind.combineK(arg1: Kind): ListK = + arrow.core.ListK.alternative().run { + this@combineK.combineK(arg1) as arrow.core.ListK +} + +@JvmName("optional") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map(::Some) + listOf(None)", "arrow.core.Some", "arrow.core.None")) +fun Kind.optional(): ListK> = arrow.core.ListK.alternative().run { + this@optional.optional() as arrow.core.ListK> +} + +@JvmName("guard") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("if (arg0) listOf(Unit) else emptyList()")) +fun guard(arg0: Boolean): ListK = arrow.core.ListK + .alternative() + .guard(arg0) as arrow.core.ListK + +@JvmName("lazyOrElse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("this + arg1()")) +fun Kind.lazyOrElse(arg1: Function0>): ListK = + arrow.core.ListK.alternative().run { + this@lazyOrElse.lazyOrElse(arg1) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Alternative typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.alternative(): ListKAlternative = alternative_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/applicative/ListKApplicative.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/applicative/ListKApplicative.kt new file mode 100644 index 000000000..38edf9c9a --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/applicative/ListKApplicative.kt @@ -0,0 +1,92 @@ +package arrow.core.extensions.listk.applicative + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKApplicative +import arrow.typeclasses.Monoid +import kotlin.Function1 +import kotlin.Int +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val applicative_singleton: ListKApplicative = object : + arrow.core.extensions.ListKApplicative {} + +@JvmName("just1") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("listOf(this)")) +fun A.just(): ListK = arrow.core.ListK.applicative().run { + this@just.just() as arrow.core.ListK +} + +@JvmName("unit") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("listOf(Unit)")) +fun unit(): ListK = arrow.core.ListK + .applicative() + .unit() as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map(arg1)")) +fun Kind.map(arg1: Function1): ListK = + arrow.core.ListK.applicative().run { + this@map.map(arg1) as arrow.core.ListK +} + +@JvmName("replicate") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("replicate(arg1)", "arrow.core.replicate")) +fun Kind.replicate(arg1: Int): ListK> = + arrow.core.ListK.applicative().run { + this@replicate.replicate(arg1) as arrow.core.ListK> +} + +@JvmName("replicate") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("replicate(arg1, arg2)", "arrow.core.replicate")) +fun Kind.replicate(arg1: Int, arg2: Monoid): ListK = + arrow.core.ListK.applicative().run { + this@replicate.replicate(arg1, arg2) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.applicative(): ListKApplicative = applicative_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/apply/ListKApply.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/apply/ListKApply.kt new file mode 100644 index 000000000..b8ea5e563 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/apply/ListKApply.kt @@ -0,0 +1,962 @@ +package arrow.core.extensions.listk.apply + +import arrow.Kind +import arrow.core.Eval +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Tuple10 +import arrow.core.Tuple2 +import arrow.core.Tuple3 +import arrow.core.Tuple4 +import arrow.core.Tuple5 +import arrow.core.Tuple6 +import arrow.core.Tuple7 +import arrow.core.Tuple8 +import arrow.core.Tuple9 +import arrow.core.extensions.ListKApply +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val apply_singleton: ListKApply = object : arrow.core.extensions.ListKApply {} + +@JvmName("ap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("_ap(arg1)", "arrow.core.ap")) +fun Kind.ap(arg1: Kind>): ListK = + arrow.core.ListK.apply().run { + this@ap.ap(arg1) as arrow.core.ListK + } + +@JvmName("apEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("arg1.map { this.ap(it.fix()) }.map { it.k() }", "arrow.core.k", "arrow.core.fix")) +fun Kind.apEval(arg1: Eval>>): + Eval> = arrow.core.ListK.apply().run { + this@apEval.apEval(arg1) as arrow.core.Eval> +} + +@JvmName("map2Eval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("apEval(arg1.map { it.fix().map { b -> { a: A -> arg2(Tuple2(a, b)) } } })", "arrow.core.k", "arrow.core.Tuple2")) +fun Kind.map2Eval( + arg1: Eval>, + arg2: Function1, Z> +): Eval> = arrow.core.ListK.apply().run { + this@map2Eval.map2Eval(arg1, arg2) as arrow.core.Eval> +} + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1).map(arg2)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2) as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1).map(arg2)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2) as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2).map(arg3)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3) as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2).map(arg3)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3) as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3).map(arg4)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4) as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3).map(arg4)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4) as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4).map(arg5)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4, arg5) as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4).map(arg5)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4, arg5) as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5).map(arg6)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4, arg5, arg6) as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5).map(arg6)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4, arg5, arg6) as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6).map(arg7)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) as + arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6).map(arg7)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) as + arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7).map(arg8)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) as + arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7).map(arg8)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) as + arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).map(arg9)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind, + arg9: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).map(arg9)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind, + arg9: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).map(arg10)", "arrow.core.tupledN")) +fun map( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind, + arg9: Kind, + arg10: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .map(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) as arrow.core.ListK + +@JvmName("mapN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).map(arg10)", "arrow.core.tupledN")) +fun mapN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind, + arg9: Kind, + arg10: Function1, Z> +): ListK = arrow.core.ListK + .apply() + .mapN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) as arrow.core.ListK + +@JvmName("map2") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map2(arg1, arg2)", "arrow.core.map2")) +fun Kind.map2(arg1: Kind, arg2: Function1, Z>): + ListK = arrow.core.ListK.apply().run { + this@map2.map2(arg1, arg2) as arrow.core.ListK +} + +@JvmName("product") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind.product(arg1: Kind): ListK> = + arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> + } + +@JvmName("product1") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): ListK> = + arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> + } + +@JvmName("product2") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): ListK> = arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> +} + +@JvmName("product3") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): + ListK> = arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> +} + +@JvmName("product4") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): + ListK> = arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> +} + +@JvmName("product5") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product( + arg1: Kind +): ListK> = arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> +} + +@JvmName("product6") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): ListK> = + arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> + } + +@JvmName("product7") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): ListK> = + arrow.core.ListK.apply().run { + this@product.product(arg1) as arrow.core.ListK> + } + +@JvmName("product8") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind>.product(arg1: Kind): ListK> = + arrow.core.ListK.apply().run { + this@product.product(arg1) as + arrow.core.ListK> + } + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1)", "arrow.core.tupledN")) +fun tupled(arg0: Kind, arg1: Kind): ListK> = + arrow.core.ListK + .apply() + .tupled(arg0, arg1) as arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1)", "arrow.core.tupledN")) +fun tupledN(arg0: Kind, arg1: Kind): ListK> = + arrow.core.ListK + .apply() + .tupledN(arg0, arg1) as arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2) as arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2) as arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3) as arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3) as arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3, arg4) as arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3, arg4) as arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3, arg4, arg5) as + arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3, arg4, arg5) as + arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3, arg4, arg5, arg6) as + arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6) as + arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) as + arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) as + arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) as + arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) as + arrow.core.ListK> + +@JvmName("tupled") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)", "arrow.core.tupledN")) +fun tupled( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind, + arg9: Kind +): ListK> = arrow.core.ListK + .apply() + .tupled(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) as + arrow.core.ListK> + +@JvmName("tupledN") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)", "arrow.core.tupledN")) +fun tupledN( + arg0: Kind, + arg1: Kind, + arg2: Kind, + arg3: Kind, + arg4: Kind, + arg5: Kind, + arg6: Kind, + arg7: Kind, + arg8: Kind, + arg9: Kind +): ListK> = arrow.core.ListK + .apply() + .tupledN(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) as + arrow.core.ListK> + +@JvmName("followedBy") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("flatMap { arg1 }")) +fun Kind.followedBy(arg1: Kind): ListK = + arrow.core.ListK.apply().run { + this@followedBy.followedBy(arg1) as arrow.core.ListK + } + +@JvmName("apTap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("ListK.mapN(this, arg1) { left, _ -> left }", "arrow.core.mapN")) +fun Kind.apTap(arg1: Kind): ListK = + arrow.core.ListK.apply().run { + this@apTap.apTap(arg1) as arrow.core.ListK + } + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Apply typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.apply(): ListKApply = apply_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/crosswalk/ListKCrosswalk.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/crosswalk/ListKCrosswalk.kt new file mode 100644 index 000000000..590abfb5c --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/crosswalk/ListKCrosswalk.kt @@ -0,0 +1,53 @@ +package arrow.core.extensions.listk.crosswalk + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKCrosswalk +import arrow.typeclasses.Align +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val crosswalk_singleton: ListKCrosswalk = object : arrow.core.extensions.ListKCrosswalk {} + +@JvmName("crosswalk") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with crosswalk, crosswalkMap or crosswalkNull from arrow.core.*") +fun crosswalk( + arg0: Align, + arg1: Kind, + arg2: Function1> +): Kind> = arrow.core.ListK + .crosswalk() + .crosswalk(arg0, arg1, arg2) as arrow.Kind> + +@JvmName("sequenceL") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with sequenceValidated or sequenceEither from arrow.core.*") +fun sequenceL(arg0: Align, arg1: Kind>): Kind> = + arrow.core.ListK + .crosswalk() + .sequenceL(arg0, arg1) as arrow.Kind> + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Crosswalk typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.crosswalk(): ListKCrosswalk = crosswalk_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/eq/ListKEq.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/eq/ListKEq.kt new file mode 100644 index 000000000..384ade335 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/eq/ListKEq.kt @@ -0,0 +1,44 @@ +package arrow.core.extensions.listk.eq + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKEq +import arrow.typeclasses.Eq +import kotlin.Boolean +import kotlin.Suppress +import kotlin.jvm.JvmName + +@JvmName("eqv") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("neqv(EQL, EQR, arg1)", "arrow.core.neqv")) +fun Kind.eqv(EQ: Eq, arg1: Kind): Boolean = + arrow.core.ListK.eq(EQ).run { + this@eqv.eqv(arg1) as kotlin.Boolean +} + +@JvmName("neqv") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("neqv(EQL, EQR, arg1)", "arrow.core.neqv")) +fun Kind.neqv(EQ: Eq, arg1: Kind): Boolean = + arrow.core.ListK.eq(EQ).run { + this@neqv.neqv(arg1) as kotlin.Boolean +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listEq(EQ)", "arrow.core.listEq")) +inline fun Companion.eq(EQ: Eq): ListKEq = object : arrow.core.extensions.ListKEq { + override fun EQ(): arrow.typeclasses.Eq = EQ } diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/eqK/ListKEqK.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/eqK/ListKEqK.kt new file mode 100644 index 000000000..907af4888 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/eqK/ListKEqK.kt @@ -0,0 +1,49 @@ +package arrow.core.extensions.listk.eqK + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKEqK +import arrow.typeclasses.Eq +import kotlin.Boolean +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val eqK_singleton: ListKEqK = object : arrow.core.extensions.ListKEqK {} + +@JvmName("eqK") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +fun Kind.eqK(arg1: Kind, arg2: Eq): Boolean = + arrow.core.ListK.eqK().run { + this@eqK.eqK(arg1, arg2) as kotlin.Boolean +} + +@JvmName("liftEq") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +fun liftEq(arg0: Eq): Eq> = arrow.core.ListK + .eqK() + .liftEq(arg0) as arrow.typeclasses.Eq> + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +inline fun Companion.eqK(): ListKEqK = eqK_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/foldable/ListKFoldable.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/foldable/ListKFoldable.kt new file mode 100644 index 000000000..a18800b2d --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/foldable/ListKFoldable.kt @@ -0,0 +1,413 @@ +package arrow.core.extensions.listk.foldable + +import arrow.Kind +import arrow.core.Eval +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Option +import arrow.core.extensions.ListKFoldable +import arrow.typeclasses.Applicative +import arrow.typeclasses.Monad +import arrow.typeclasses.Monoid +import kotlin.Boolean +import kotlin.Function1 +import kotlin.Function2 +import kotlin.Long +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.collections.List +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val foldable_singleton: ListKFoldable = object : arrow.core.extensions.ListKFoldable {} + +@JvmName("foldLeft") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("fold(arg1, arg2)")) +fun Kind.foldLeft(arg1: B, arg2: Function2): B = + arrow.core.ListK.foldable().run { + this@foldLeft.foldLeft(arg1, arg2) as B + } + +@JvmName("foldRight") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("foldRight(arg1, arg2)", "arrow.core.foldRight")) +fun Kind.foldRight(arg1: Eval, arg2: Function2, Eval>): Eval = + arrow.core.ListK.foldable().run { + this@foldRight.foldRight(arg1, arg2) as arrow.core.Eval + } + +@JvmName("fold") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("combineAll(arg1)", "arrow.core.combineAll")) +fun Kind.fold(arg1: Monoid): A = arrow.core.ListK.foldable().run { + this@fold.fold(arg1) as A +} + +@JvmName("reduceLeftToOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(reduceNullable(arg1, arg2))", "arrow.core.reduceNullable", "arrow.core.Option")) +fun Kind.reduceLeftToOption(arg1: Function1, arg2: Function2): + Option = arrow.core.ListK.foldable().run { + this@reduceLeftToOption.reduceLeftToOption(arg1, arg2) as arrow.core.Option +} + +@JvmName("reduceRightToOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("reduceRightNullable(arg1, arg2).map { Option.fromNullable(it) }", "arrow.core.reduceRightNullable", "arrow.core.Option")) +fun Kind.reduceRightToOption( + arg1: Function1, + arg2: Function2, + Eval> +): Eval> = arrow.core.ListK.foldable().run { + this@reduceRightToOption.reduceRightToOption(arg1, arg2) as + arrow.core.Eval> +} + +@JvmName("reduceLeftOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith(" Option.fromNullable(reduceNullable({ it }, arg1))", "arrow.core.reduceNullable", "arrow.core.Option")) +fun Kind.reduceLeftOption(arg1: Function2): Option = + arrow.core.ListK.foldable().run { + this@reduceLeftOption.reduceLeftOption(arg1) as arrow.core.Option + } + +@JvmName("reduceRightOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("reduceRightOption({ it }, arg2).map { Option.fromNullable(it) }", "arrow.core.reduceRightNullable", "arrow.core.Option")) +fun Kind.reduceRightOption(arg1: Function2, Eval>): Eval> = + arrow.core.ListK.foldable().run { + this@reduceRightOption.reduceRightOption(arg1) as arrow.core.Eval> + } + +@JvmName("combineAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("combineAll(arg1)", "arrow.core.combineAll")) +fun Kind.combineAll(arg1: Monoid): A = arrow.core.ListK.foldable().run { + this@combineAll.combineAll(arg1) as A +} + +@JvmName("foldMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("foldMap(arg1, arg2)", "arrow.core.foldMap")) +fun Kind.foldMap(arg1: Monoid, arg2: Function1): B = + arrow.core.ListK.foldable().run { + this@foldMap.foldMap(arg1, arg2) as B + } + +@JvmName("orEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listOf(arg1.empty())")) +fun orEmpty(arg0: Applicative, arg1: Monoid): ListK = arrow.core.ListK + .foldable() + .orEmpty(arg0, arg1) as arrow.core.ListK + +@JvmName("traverse_") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with traverseValidated_ or traverseEither_ from arrow.core.*") +fun Kind.traverse_(arg1: Applicative, arg2: Function1>): + Kind = arrow.core.ListK.foldable().run { + this@traverse_.traverse_(arg1, arg2) as arrow.Kind +} + +@JvmName("sequence_") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with sequenceValidated_ or sequenceEither_ from arrow.core.*") +fun Kind>.sequence_(arg1: Applicative): Kind = + arrow.core.ListK.foldable().run { + this@sequence_.sequence_(arg1) as arrow.Kind + } + +@JvmName("find") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull(arg1))", "arrow.core.Option")) +fun Kind.find(arg1: Function1): Option = + arrow.core.ListK.foldable().run { + this@find.find(arg1) as arrow.core.Option + } + +@JvmName("exists") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("any(arg1)")) +fun Kind.exists(arg1: Function1): Boolean = + arrow.core.ListK.foldable().run { + this@exists.exists(arg1) as kotlin.Boolean + } + +@JvmName("forAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("all(arg1)")) +fun Kind.forAll(arg1: Function1): Boolean = + arrow.core.ListK.foldable().run { + this@forAll.forAll(arg1) as kotlin.Boolean + } + +@JvmName("all") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("all(arg1)")) +fun Kind.all(arg1: Function1): Boolean = + arrow.core.ListK.foldable().run { + this@all.all(arg1) as kotlin.Boolean + } + +@JvmName("isEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("isEmpty()")) +fun Kind.isEmpty(): Boolean = arrow.core.ListK.foldable().run { + this@isEmpty.isEmpty() as kotlin.Boolean +} + +@JvmName("nonEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("isNotEmpty()")) +fun Kind.nonEmpty(): Boolean = arrow.core.ListK.foldable().run { + this@nonEmpty.nonEmpty() as kotlin.Boolean +} + +@JvmName("isNotEmpty") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("isNotEmpty()")) +fun Kind.isNotEmpty(): Boolean = arrow.core.ListK.foldable().run { + this@isNotEmpty.isNotEmpty() as kotlin.Boolean +} + +@JvmName("size") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("size")) +fun Kind.size(arg1: Monoid): Long = arrow.core.ListK.foldable().run { + this@size.size(arg1) as kotlin.Long +} + +@JvmName("foldMapA") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +fun , MO : Monoid> Kind.foldMapA( + arg1: AP, + arg2: MO, + arg3: Function1> +): Kind = arrow.core.ListK.foldable().run { + this@foldMapA.foldMapA(arg1, arg2, arg3) as arrow.Kind +} + +@JvmName("foldMapM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +fun , MO : Monoid> Kind.foldMapM( + arg1: MA, + arg2: MO, + arg3: Function1> +): Kind = arrow.core.ListK.foldable().run { + this@foldMapM.foldMapM(arg1, arg2, arg3) as arrow.Kind +} + +@JvmName("foldM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Applicative typeclasses is deprecated. Use concrete methods on List") +fun Kind.foldM( + arg1: Monad, + arg2: B, + arg3: Function2> +): Kind = arrow.core.ListK.foldable().run { + this@foldM.foldM(arg1, arg2, arg3) as arrow.Kind +} + +@JvmName("get") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("[arg1]")) +fun Kind.get(arg1: Long): Option = arrow.core.ListK.foldable().run { + this@get.get(arg1) as arrow.core.Option +} + +@JvmName("firstOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull())", "arrow.core.Option")) +fun Kind.firstOption(): Option = arrow.core.ListK.foldable().run { + this@firstOption.firstOption() as arrow.core.Option +} + +@JvmName("firstOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull(arg1))", "arrow.core.Option")) +fun Kind.firstOption(arg1: Function1): Option = + arrow.core.ListK.foldable().run { + this@firstOption.firstOption(arg1) as arrow.core.Option + } + +@JvmName("firstOrNone") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull())", "arrow.core.Option")) +fun Kind.firstOrNone(): Option = arrow.core.ListK.foldable().run { + this@firstOrNone.firstOrNone() as arrow.core.Option +} + +@JvmName("firstOrNone") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("Option.fromNullable(firstOrNull(arg1))", "arrow.core.Option")) +fun Kind.firstOrNone(arg1: Function1): Option = + arrow.core.ListK.foldable().run { + this@firstOrNone.firstOrNone(arg1) as arrow.core.Option + } + +@JvmName("toList") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("this")) +fun Kind.toList(): List = arrow.core.ListK.foldable().run { + this@toList.toList() as kotlin.collections.List +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Foldable typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.foldable(): ListKFoldable = foldable_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/functor/ListKFunctor.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/functor/ListKFunctor.kt new file mode 100644 index 000000000..5d1eed700 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/functor/ListKFunctor.kt @@ -0,0 +1,199 @@ +package arrow.core.extensions.listk.functor + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKFunctor +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val functor_singleton: ListKFunctor = object : arrow.core.extensions.ListKFunctor {} + +/** + * Transform the [F] wrapped value [A] into [B] preserving the [F] structure + * Kind -> Kind + * + * ```kotlin:ank:playground + * import arrow.core.* + * import arrow.core.extensions.listk.functor.* + * import arrow.core.* + * + * + * import arrow.core.extensions.listk.applicative.just + * + * fun main(args: Array) { + * val result = + * //sampleStart + * "Hello".just().map({ "$it World" }) + * //sampleEnd + * println(result) + * } + * ``` + */ +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("map(arg1)")) +fun Kind.map(arg1: Function1): ListK = arrow.core.ListK.functor().run { + this@map.map(arg1) as arrow.core.ListK +} + +@JvmName("imap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("map(arg1)")) +fun Kind.imap(arg1: Function1, arg2: Function1): ListK = + arrow.core.ListK.functor().run { + this@imap.imap(arg1, arg2) as arrow.core.ListK +} + +/** + * Lifts a function `A -> B` to the [F] structure returning a polymorphic function + * that can be applied over all [F] values in the shape of Kind + * + * `A -> B -> Kind -> Kind` + * + * ```kotlin:ank:playground + * import arrow.core.* + * import arrow.core.extensions.listk.functor.* + * import arrow.core.* + * + * + * import arrow.core.extensions.listk.applicative.just + * + * fun main(args: Array) { + * val result = + * //sampleStart + * lift({ s: CharSequence -> "$s World" })("Hello".just()) + * //sampleEnd + * println(result) + * } + * ``` + */ +@JvmName("lift") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("{ l: List -> l.map(arg0) }")) +fun lift(arg0: Function1): Function1, Kind> = + arrow.core.ListK + .functor() + .lift(arg0) as kotlin.Function1, + arrow.Kind> + +@JvmName("void") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("void()", "arrow.core.void")) +fun Kind.void(): ListK = arrow.core.ListK.functor().run { + this@void.void() as arrow.core.ListK +} + +@JvmName("fproduct") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("fproduct(arg1)", "arrow.core.fproduct")) +fun Kind.fproduct(arg1: Function1): ListK> = + arrow.core.ListK.functor().run { + this@fproduct.fproduct(arg1) as arrow.core.ListK> +} + +@JvmName("mapConst") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapConst(arg1)", "arrow.core.mapConst")) +fun Kind.mapConst(arg1: B): ListK = arrow.core.ListK.functor().run { + this@mapConst.mapConst(arg1) as arrow.core.ListK +} + +/** + * Replaces the [B] value inside [F] with [A] resulting in a Kind + */ +@JvmName("mapConst") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg1.mapConst(this)", "arrow.core.mapConst")) +fun A.mapConst(arg1: Kind): ListK = arrow.core.ListK.functor().run { + this@mapConst.mapConst(arg1) as arrow.core.ListK +} + +@JvmName("tupleLeft") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("tupleLeft(arg1)", "arrow.core.tupleLeft")) +fun Kind.tupleLeft(arg1: B): ListK> = + arrow.core.ListK.functor().run { + this@tupleLeft.tupleLeft(arg1) as arrow.core.ListK> +} + +@JvmName("tupleRight") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("tupleRight(arg1)", "arrow.core.tupleRight")) +fun Kind.tupleRight(arg1: B): ListK> = + arrow.core.ListK.functor().run { + this@tupleRight.tupleRight(arg1) as arrow.core.ListK> +} + +@JvmName("widen") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("widen()", "arrow.core.widen")) +fun Kind.widen(): ListK = arrow.core.ListK.functor().run { + this@widen.widen() as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Functor typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.functor(): ListKFunctor = functor_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/functorFilter/ListKFunctorFilter.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/functorFilter/ListKFunctorFilter.kt new file mode 100644 index 000000000..a14b3b2b7 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/functorFilter/ListKFunctorFilter.kt @@ -0,0 +1,78 @@ +package arrow.core.extensions.listk.functorFilter + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Option +import arrow.core.extensions.ListKFunctorFilter +import java.lang.Class +import kotlin.Boolean +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val functorFilter_singleton: ListKFunctorFilter = object : + arrow.core.extensions.ListKFunctorFilter {} + +@JvmName("filterMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapNotNull { arg1(it).orNull() }")) +fun Kind.filterMap(arg1: Function1>): ListK = + arrow.core.ListK.functorFilter().run { + this@filterMap.filterMap(arg1) as arrow.core.ListK +} + +@JvmName("flattenOption") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +fun Kind>.flattenOption(): ListK = arrow.core.ListK.functorFilter().run { + this@flattenOption.flattenOption() as arrow.core.ListK +} + +@JvmName("filter") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapNotNull { it.orNull() }")) +fun Kind.filter(arg1: Function1): ListK = + arrow.core.ListK.functorFilter().run { + this@filter.filter(arg1) as arrow.core.ListK +} + +@JvmName("filterIsInstance") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("filter(arg1::isInstance).map { arg1.cast(it) }")) +fun Kind.filterIsInstance(arg1: Class): ListK = + arrow.core.ListK.functorFilter().run { + this@filterIsInstance.filterIsInstance(arg1) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Functor typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.functorFilter(): ListKFunctorFilter = functorFilter_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/hash/ListKHash.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/hash/ListKHash.kt new file mode 100644 index 000000000..a41014e50 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/hash/ListKHash.kt @@ -0,0 +1,43 @@ +package arrow.core.extensions.listk.hash + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKHash +import arrow.typeclasses.Hash +import kotlin.Int +import kotlin.Suppress +import kotlin.jvm.JvmName + +@JvmName("hash") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("hash(HA)", "arrow.core.hash")) +fun Kind.hash(HA: Hash): Int = arrow.core.ListK.hash(HA).run { + this@hash.hash() as kotlin.Int +} + +@JvmName("hashWithSalt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("hashWithSalt(HA, arg1)", "arrow.core.hashWithSalt")) +fun Kind.hashWithSalt(HA: Hash, arg1: Int): Int = + arrow.core.ListK.hash(HA).run { + this@hashWithSalt.hashWithSalt(arg1) as kotlin.Int +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listHash(HA)", "arrow.core.listHash")) +inline fun Companion.hash(HA: Hash): ListKHash = object : + arrow.core.extensions.ListKHash { override fun HA(): arrow.typeclasses.Hash = HA } diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monad/ListKMonad.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monad/ListKMonad.kt new file mode 100644 index 000000000..fc8df2a1c --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monad/ListKMonad.kt @@ -0,0 +1,280 @@ +package arrow.core.extensions.listk.monad + +import arrow.Kind +import arrow.core.Either +import arrow.core.Eval +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKMonad +import kotlin.Boolean +import kotlin.Function0 +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monad_singleton: ListKMonad = object : arrow.core.extensions.ListKMonad {} + +@JvmName("flatMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap(arg1)")) +fun Kind.flatMap(arg1: Function1>): ListK = + arrow.core.ListK.monad().run { + this@flatMap.flatMap(arg1) as arrow.core.ListK +} + +@JvmName("tailRecM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("tailRecMIterable(arg0) { arg1(it) }")) +fun tailRecM(arg0: A, arg1: Function1>>): ListK = + arrow.core.ListK + .monad() + .tailRecM(arg0, arg1) as arrow.core.ListK + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("map(arg1)")) +fun Kind.map(arg1: Function1): ListK = arrow.core.ListK.monad().run { + this@map.map(arg1) as arrow.core.ListK +} + +/** + * @see [Apply.ap] + */ +@JvmName("ap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("ap(arg1)", "arrow.core.ap")) +fun Kind.ap(arg1: Kind>): ListK = + arrow.core.ListK.monad().run { + this@ap.ap(arg1) as arrow.core.ListK +} + +@JvmName("flatten") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatten")) +fun Kind>.flatten(): ListK = arrow.core.ListK.monad().run { + this@flatten.flatten() as arrow.core.ListK +} + +@JvmName("followedBy") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { arg1 }")) +fun Kind.followedBy(arg1: Kind): ListK = + arrow.core.ListK.monad().run { + this@followedBy.followedBy(arg1) as arrow.core.ListK +} + +@JvmName("apTap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.map { a } }")) +fun Kind.apTap(arg1: Kind): ListK = + arrow.core.ListK.monad().run { + this@apTap.apTap(arg1) as arrow.core.ListK +} + +@JvmName("followedByEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { arg1.value() }")) +fun Kind.followedByEval(arg1: Eval>): ListK = + arrow.core.ListK.monad().run { + this@followedByEval.followedByEval(arg1) as arrow.core.ListK +} + +@JvmName("effectM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1(a).map { a } }")) +fun Kind.effectM(arg1: Function1>): ListK = + arrow.core.ListK.monad().run { + this@effectM.effectM(arg1) as arrow.core.ListK +} + +@JvmName("flatTap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1(a).map { a } }")) +fun Kind.flatTap(arg1: Function1>): ListK = + arrow.core.ListK.monad().run { + this@flatTap.flatTap(arg1) as arrow.core.ListK +} + +@JvmName("productL") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.map { a } }")) +fun Kind.productL(arg1: Kind): ListK = + arrow.core.ListK.monad().run { + this@productL.productL(arg1) as arrow.core.ListK +} + +@JvmName("forEffect") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.map { a } }")) +fun Kind.forEffect(arg1: Kind): ListK = + arrow.core.ListK.monad().run { + this@forEffect.forEffect(arg1) as arrow.core.ListK +} + +@JvmName("productLEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.value().map { a } }")) +fun Kind.productLEval(arg1: Eval>): ListK = + arrow.core.ListK.monad().run { + this@productLEval.productLEval(arg1) as arrow.core.ListK +} + +@JvmName("forEffectEval") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1.value().map { a } }")) +fun Kind.forEffectEval(arg1: Eval>): ListK = + arrow.core.ListK.monad().run { + this@forEffectEval.forEffectEval(arg1) as arrow.core.ListK +} + +@JvmName("mproduct") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("flatMap { a -> arg1(a).map { b -> Tuple2(a, b) } }")) +fun Kind.mproduct(arg1: Function1>): ListK> = + arrow.core.ListK.monad().run { + this@mproduct.mproduct(arg1) as arrow.core.ListK> +} + +@JvmName("ifM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("ifM(arg1, arg2)", "arrow.core.ifM")) +fun Kind.ifM( + arg1: Function0>, + arg2: Function0> +): ListK = arrow.core.ListK.monad().run { + this@ifM.ifM(arg1, arg2) as arrow.core.ListK +} + +@JvmName("selectM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("selectM(arg1)", "arrow.core.selectM")) +fun Kind>.selectM(arg1: Kind>): ListK = + arrow.core.ListK.monad().run { + this@selectM.selectM(arg1) as arrow.core.ListK +} + +@JvmName("select") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("select(arg1)", "arrow.core.select")) +fun Kind>.select(arg1: Kind>): ListK = + arrow.core.ListK.monad().run { + this@select.select(arg1) as arrow.core.ListK +} + +/** + * ank_macro_hierarchy(arrow.typeclasses.Monad) + * + * [Monad] abstract over the ability to declare sequential computations that are dependent in the order or + * the results of previous computations. + * + * Given a type constructor [F] with a value of [A] we can compose multiple operations of type + * `Kind` where `?` denotes a value being transformed. + * + * This is true for all type constructors that can support the [Monad] type class including and not limited to + * [IO], [ObservableK], [Option], [Either], [List] ... + * + * [The Monad Tutorial](https://arrow-kt.io/docs/patterns/monads/) + */ +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Monad typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.monad(): ListKMonad = monad_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadCombine/ListKMonadCombine.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadCombine/ListKMonadCombine.kt new file mode 100644 index 000000000..a12d19507 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadCombine/ListKMonadCombine.kt @@ -0,0 +1,54 @@ +package arrow.core.extensions.listk.monadCombine + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKMonadCombine +import arrow.typeclasses.Bifoldable +import arrow.typeclasses.Foldable +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monadCombine_singleton: ListKMonadCombine = object : + arrow.core.extensions.ListKMonadCombine {} + +@JvmName("unite") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Foldable typeclasses is deprecated. Use concrete methods on List") +fun Kind>.unite(arg1: Foldable): ListK = + arrow.core.ListK.monadCombine().run { + this@unite.unite(arg1) as arrow.core.ListK +} + +@JvmName("separate") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Foldable typeclasses is deprecated. Use concrete methods on List") +fun Kind, B>>.separate(arg1: Bifoldable): + Tuple2, Kind> = arrow.core.ListK.monadCombine().run { + this@separate.separate(arg1) as arrow.core.Tuple2, + arrow.Kind> +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("MonadCombine typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.monadCombine(): ListKMonadCombine = monadCombine_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadFilter/ListKMonadFilter.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadFilter/ListKMonadFilter.kt new file mode 100644 index 000000000..9f456c6ce --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadFilter/ListKMonadFilter.kt @@ -0,0 +1,53 @@ +package arrow.core.extensions.listk.monadFilter + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Option +import arrow.core.extensions.ListKMonadFilter +import arrow.typeclasses.MonadFilterSyntax +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monadFilter_singleton: ListKMonadFilter = object : + arrow.core.extensions.ListKMonadFilter {} + +@JvmName("filterMap") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("mapNotNull { arg1(it).orNull() }")) +fun Kind.filterMap(arg1: Function1>): ListK = + arrow.core.ListK.monadFilter().run { + this@filterMap.filterMap(arg1) as arrow.core.ListK +} + +@JvmName("bindingFilter") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("Monad bindings are deprecated") +fun bindingFilter(arg0: suspend MonadFilterSyntax.() -> B): ListK = + arrow.core.ListK + .monadFilter() + .bindingFilter(arg0) as arrow.core.ListK + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("MonadFilter typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.monadFilter(): ListKMonadFilter = monadFilter_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadLogic/ListKMonadLogic.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadLogic/ListKMonadLogic.kt new file mode 100644 index 000000000..27859123a --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadLogic/ListKMonadLogic.kt @@ -0,0 +1,105 @@ +package arrow.core.extensions.listk.monadLogic + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Option +import arrow.core.Tuple2 +import arrow.core.extensions.ListKMonadLogic +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.Unit +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monadLogic_singleton: ListKMonadLogic = object : arrow.core.extensions.ListKMonadLogic + {} + +@JvmName("splitM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("split()", "arrow.core.split()")) +fun Kind.splitM(): ListK, A>>> = + arrow.core.ListK.monadLogic().run { + this@splitM.splitM() as + arrow.core.ListK, A>>> +} + +@JvmName("interleave") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("interleave(arg1)", "arrow.core.interleave")) +fun Kind.interleave(arg1: Kind): ListK = + arrow.core.ListK.monadLogic().run { + this@interleave.interleave(arg1) as arrow.core.ListK +} + +@JvmName("unweave") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("unweave(arg1)", "arrow.core.unweave")) +fun Kind.unweave(arg1: Function1>): ListK = + arrow.core.ListK.monadLogic().run { + this@unweave.unweave(arg1) as arrow.core.ListK +} + +@JvmName("ifThen") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("ifThen(arg1, arg2)", "arrow.core.ifThen")) +fun Kind.ifThen(arg1: Kind, arg2: Function1>): + ListK = arrow.core.ListK.monadLogic().run { + this@ifThen.ifThen(arg1, arg2) as arrow.core.ListK +} + +@JvmName("once") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listOfNotNull(firstOrNull())")) +fun Kind.once(): ListK = arrow.core.ListK.monadLogic().run { + this@once.once() as arrow.core.ListK +} + +@JvmName("voidIfValue") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("firstOrNull()?.let { emptyList() } ?: listOf(Unit)")) +fun Kind.voidIfValue(): ListK = arrow.core.ListK.monadLogic().run { + this@voidIfValue.voidIfValue() as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("MonadLogic typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.monadLogic(): ListKMonadLogic = monadLogic_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadPlus/ListKMonadPlus.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadPlus/ListKMonadPlus.kt new file mode 100644 index 000000000..c7129f6fe --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monadPlus/ListKMonadPlus.kt @@ -0,0 +1,48 @@ +package arrow.core.extensions.listk.monadPlus + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKMonadPlus +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monadPlus_singleton: ListKMonadPlus = object : arrow.core.extensions.ListKMonadPlus {} + +@JvmName("zeroM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("emptyList()")) +fun zeroM(): ListK = arrow.core.ListK + .monadPlus() + .zeroM() as arrow.core.ListK + +@JvmName("plusM") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("this + arg1")) +fun Kind.plusM(arg1: Kind): ListK = + arrow.core.ListK.monadPlus().run { + this@plusM.plusM(arg1) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("MonadPlus typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.monadPlus(): ListKMonadPlus = monadPlus_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoid/ListKMonoid.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoid/ListKMonoid.kt new file mode 100644 index 000000000..21546cc89 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoid/ListKMonoid.kt @@ -0,0 +1,49 @@ +package arrow.core.extensions.listk.monoid + +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKMonoid +import kotlin.Any +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.collections.Collection +import kotlin.collections.List +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monoid_singleton: ListKMonoid = object : ListKMonoid {} + +@JvmName("combineAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.fold(emptyList()) { acc, l -> acc + l }")) +fun Collection>.combineAll(): ListK = arrow.core.ListK.monoid().run { + this@combineAll.combineAll() as arrow.core.ListK +} + +@JvmName("combineAll") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.fold(emptyList()) { acc, l -> acc + l }")) +fun combineAll(arg0: List>): ListK = arrow.core.ListK + .monoid() + .combineAll(arg0) as arrow.core.ListK + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) +inline fun Companion.monoid(): ListKMonoid = monoid_singleton as + arrow.core.extensions.ListKMonoid diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoidK/ListKMonoidK.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoidK/ListKMonoidK.kt new file mode 100644 index 000000000..837da958a --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoidK/ListKMonoidK.kt @@ -0,0 +1,35 @@ +package arrow.core.extensions.listk.monoidK + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKMonoidK +import arrow.typeclasses.Monoid +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monoidK_singleton: ListKMonoidK = object : arrow.core.extensions.ListKMonoidK {} + +@JvmName("algebra") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) +fun algebra(): Monoid> = arrow.core.ListK + .monoidK() + .algebra() as arrow.typeclasses.Monoid> + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +inline fun Companion.monoidK(): ListKMonoidK = monoidK_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoidal/ListKMonoidal.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoidal/ListKMonoidal.kt new file mode 100644 index 000000000..0af7da54b --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/monoidal/ListKMonoidal.kt @@ -0,0 +1,33 @@ +package arrow.core.extensions.listk.monoidal + +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKMonoidal +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val monoidal_singleton: ListKMonoidal = object : arrow.core.extensions.ListKMonoidal {} + +@JvmName("identity") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("emptyList()")) +fun identity(): ListK = arrow.core.ListK + .monoidal() + .identity() as arrow.core.ListK + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Monoidal typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.monoidal(): ListKMonoidal = monoidal_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/order/ListKOrder.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/order/ListKOrder.kt new file mode 100644 index 000000000..b9cd4b650 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/order/ListKOrder.kt @@ -0,0 +1,153 @@ +package arrow.core.extensions.listk.order + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Ordering +import arrow.core.Tuple2 +import arrow.core.extensions.ListKOrder +import arrow.typeclasses.Order +import kotlin.Boolean +import kotlin.Int +import kotlin.Suppress +import kotlin.jvm.JvmName + +@JvmName("compare") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("compare(OA, arg1)", "arrow.core.compare")) +fun Kind.compare(OA: Order, arg1: Kind): Ordering = + arrow.core.ListK.order(OA).run { + this@compare.compare(arg1) as arrow.core.Ordering +} + +@JvmName("compareTo") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("compareTo(OA, arg1)", "arrow.core.compareTo")) +fun Kind.compareTo(OA: Order, arg1: Kind): Int = + arrow.core.ListK.order(OA).run { + this@compareTo.compareTo(arg1) as kotlin.Int +} + +@JvmName("eqv") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("eqv(OA, arg1)", "arrow.core.eqv")) +fun Kind.eqv(OA: Order, arg1: Kind): Boolean = + arrow.core.ListK.order(OA).run { + this@eqv.eqv(arg1) as kotlin.Boolean +} + +@JvmName("lt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("lt(OA, arg1)", "arrow.core.lt")) +fun Kind.lt(OA: Order, arg1: Kind): Boolean = + arrow.core.ListK.order(OA).run { + this@lt.lt(arg1) as kotlin.Boolean +} + +@JvmName("lte") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("lte(OA, arg1)", "arrow.core.lte")) +fun Kind.lte(OA: Order, arg1: Kind): Boolean = + arrow.core.ListK.order(OA).run { + this@lte.lte(arg1) as kotlin.Boolean +} + +@JvmName("gt") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("gt(OA, arg1)", "arrow.core.gt")) +fun Kind.gt(OA: Order, arg1: Kind): Boolean = + arrow.core.ListK.order(OA).run { + this@gt.gt(arg1) as kotlin.Boolean +} + +@JvmName("gte") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("gte(OA, arg1)", "arrow.core.gte")) +fun Kind.gte(OA: Order, arg1: Kind): Boolean = + arrow.core.ListK.order(OA).run { + this@gte.gte(arg1) as kotlin.Boolean +} + +@JvmName("max") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("max(OA, arg1)", "arrow.core.max")) +fun Kind.max(OA: Order, arg1: Kind): ListK = + arrow.core.ListK.order(OA).run { + this@max.max(arg1) as arrow.core.ListK +} + +@JvmName("min") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("min(OA, arg1)", "arrow.core.min")) +fun Kind.min(OA: Order, arg1: Kind): ListK = + arrow.core.ListK.order(OA).run { + this@min.min(arg1) as arrow.core.ListK +} + +@JvmName("sort") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("sort(OA, arg1)", "arrow.core.sort")) +fun Kind.sort(OA: Order, arg1: Kind): Tuple2, + Kind> = arrow.core.ListK.order(OA).run { + this@sort.sort(arg1) as arrow.core.Tuple2, + arrow.Kind> +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listOrder(OA)", "arrow.core.listOrder")) +inline fun Companion.order(OA: Order): ListKOrder = object : + arrow.core.extensions.ListKOrder { override fun OA(): arrow.typeclasses.Order = OA } diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semialign/ListKSemialign.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semialign/ListKSemialign.kt new file mode 100644 index 000000000..a9c323113 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semialign/ListKSemialign.kt @@ -0,0 +1,101 @@ +package arrow.core.extensions.listk.semialign + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.Ior +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Option +import arrow.core.Tuple2 +import arrow.core.extensions.ListKSemialign +import arrow.typeclasses.Semigroup +import kotlin.Function1 +import kotlin.Function2 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val semialign_singleton: ListKSemialign = object : arrow.core.extensions.ListKSemialign {} + +@JvmName("align") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.align(arg1)", "arrow.core.align")) +fun align(arg0: Kind, arg1: Kind): ListK> = + arrow.core.ListK + .semialign() + .align(arg0, arg1) as arrow.core.ListK> + +@JvmName("alignWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.alignWith(arg1, arg2)", "arrow.core.alignWith")) +fun alignWith( + arg0: Kind, + arg1: Kind, + arg2: Function1, C> +): ListK = arrow.core.ListK + .semialign() + .alignWith(arg0, arg1, arg2) as arrow.core.ListK + +@JvmName("salign") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.salign(arg1, arg2)", "arrow.core.salign")) +fun Kind.salign(arg1: Semigroup, arg2: Kind): ListK = + arrow.core.ListK.semialign().run { + this@salign.salign(arg1, arg2) as arrow.core.ListK + } + +@JvmName("padZip") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.padZip(arg1)", "arrow.core.padZip")) +fun Kind.padZip(arg1: Kind): ListK, Option>> = + arrow.core.ListK.semialign().run { + this@padZip.padZip(arg1) as arrow.core.ListK, + arrow.core.Option>> + } + +@JvmName("padZipWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.padZipWith(arg1, arg2)", "arrow.core.padZipWith")) +fun Kind.padZipWith( + arg1: Kind, + arg2: Function2, + Option, C> +): ListK = arrow.core.ListK.semialign().run { + this@padZipWith.padZipWith(arg1, arg2) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Semialign typeclasses is deprecated. Use concrete methods on List") +inline fun Companion.semialign(): ListKSemialign = semialign_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroup/ListKSemigroup.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroup/ListKSemigroup.kt new file mode 100644 index 000000000..863c0a374 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroup/ListKSemigroup.kt @@ -0,0 +1,47 @@ +package arrow.core.extensions.listk.semigroup + +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKSemigroup +import kotlin.Any +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val semigroup_singleton: ListKSemigroup = object : ListKSemigroup {} + +@JvmName("plus") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("this.plus(arg1)")) +operator fun ListK.plus(arg1: ListK): ListK = arrow.core.ListK.semigroup().run { + this@plus.plus(arg1) as arrow.core.ListK +} + +@JvmName("maybeCombine") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("(arg1?.plus(this) ?: emptyList())")) +fun ListK.maybeCombine(arg1: ListK): ListK = arrow.core.ListK.semigroup().run { + this@maybeCombine.maybeCombine(arg1) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) +inline fun Companion.semigroup(): ListKSemigroup = semigroup_singleton as + arrow.core.extensions.ListKSemigroup diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroupK/ListKSemigroupK.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroupK/ListKSemigroupK.kt new file mode 100644 index 000000000..fdeb2746f --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroupK/ListKSemigroupK.kt @@ -0,0 +1,50 @@ +package arrow.core.extensions.listk.semigroupK + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKSemigroupK +import arrow.typeclasses.Semigroup +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val semigroupK_singleton: ListKSemigroupK = object : arrow.core.extensions.ListKSemigroupK + {} + +@JvmName("combineK") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind.combineK(arg1: Kind): ListK = + arrow.core.ListK.semigroupK().run { + this@combineK.combineK(arg1) as arrow.core.ListK +} + +@JvmName("algebra") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listMonoid()", "arrow.core.listMonoid")) +fun algebra(): Semigroup> = arrow.core.ListK + .semigroupK() + .algebra() as arrow.typeclasses.Semigroup> + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +inline fun Companion.semigroupK(): ListKSemigroupK = semigroupK_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroupal/ListKSemigroupal.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroupal/ListKSemigroupal.kt new file mode 100644 index 000000000..ddce37ad2 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/semigroupal/ListKSemigroupal.kt @@ -0,0 +1,148 @@ +package arrow.core.extensions.listk.semigroupal + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKSemigroupal +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val semigroupal_singleton: ListKSemigroupal = object : + arrow.core.extensions.ListKSemigroupal {} + +/** + * Multiplicatively combine F and F into F> + */ +@JvmName("product") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +fun Kind.product(arg1: Kind): ListK> = + arrow.core.ListK.semigroupal().run { + this@product.product(arg1) as arrow.core.ListK> +} + +/** + * syntax + */ +@JvmName("times") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("product(arg1)", "arrow.core.product")) +operator fun Kind.times(arg1: Kind): ListK> = + arrow.core.ListK.semigroupal().run { + this@times.times(arg1) as arrow.core.ListK> +} + +/** + * ank_macro_hierarchy(arrow.typeclasses.Semigroupal) + * + * The [Semigroupal] type class for a given type `F` can be seen as an abstraction over the [cartesian product](https://en.wikipedia.org/wiki/Cartesian_product). + * It defines the function [product]. + * + * The [product] function for a given type `F`, `A` and `B` combines a `Kind` and a `Kind` into a `Kind>`. + * This function guarantees compliance with the following laws: + * + * [Semigroupal]s are associative under the bijection `f = (a,(b,c)) -> ((a,b),c)` or `f = ((a,b),c) -> (a,(b,c))`. + * Therefore, the following laws also apply: + * + * ```kotlin + * f((a.product(b)).product(c)) == a.product(b.product(c)) + * ``` + * + * ```kotlin + * f(a.product(b.product(c))) == (a.product(b)).product(c) + * ``` + * + * Currently, [Semigroupal] instances are defined for [Option], [ListK], [SequenceK] and [SetK]. + * + * ```kotlin:ank:playground + * import arrow.core.* + * import arrow.core.extensions.listk.semigroupal.* + * import arrow.core.* + * + * + * + * fun main(args: Array) { + * val result = + * //sampleStart + * ListK.semigroupal() + * //sampleEnd + * println(result) + * } + * ``` + * + * ### Examples + * + * Here a some examples: + * + * ```kotlin:ank:playground + * import arrow.core.Option + * import arrow.core.extensions.option.semigroupal.semigroupal + * + * fun main(args: Array) { + * val result = + * //sampleStart + * Option.semigroupal().run { + * Option.just(1).product(Option.just(1)) + * } + * //sampleEnd + * println(result) + * } + * ``` + * + * [Semigroupal] also has support of the `*` syntax: + * + * ```kotlin:ank:playground + * import arrow.core.Option + * import arrow.core.extensions.option.semigroupal.semigroupal + * + * fun main(args: Array) { + * val result = + * //sampleStart + * Option.semigroupal().run { + * Option.just(2) + * } + * //sampleEnd + * println(result) + * } + * ``` + * The same applies to [ListK], [SequenceK] and [SetK] instances: + * + * ```kotlin:ank:playground + * import arrow.core.ListK + * import arrow.core.extensions.listk.semigroupal.semigroupal + * import arrow.core.k + * + * fun main(args: Array) { + * val result = + * //sampleStart + * ListK.semigroupal().run { + * listOf('a','b','c').k() + * } + * //sampleEnd + * println(result) + * } + * ``` + */ +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Kind/type constructors will be deprecated, so this typeclass will no longer be available from 0.13.0") +inline fun Companion.semigroupal(): ListKSemigroupal = semigroupal_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/show/ListKShow.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/show/ListKShow.kt new file mode 100644 index 000000000..31915eb27 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/show/ListKShow.kt @@ -0,0 +1,30 @@ +package arrow.core.extensions.listk.show + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKShow +import arrow.typeclasses.Show +import kotlin.String +import kotlin.Suppress +import kotlin.jvm.JvmName + +@JvmName("show") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("show(arg1)", "arrow.core.show")) +fun Kind.show(SA: Show): String = arrow.core.ListK.show(SA).run { + this@show.show() as kotlin.String +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("listShow(arg1)", "arrow.core.listShow")) +inline fun Companion.show(SA: Show): ListKShow = object : + arrow.core.extensions.ListKShow { override fun SA(): arrow.typeclasses.Show = SA } diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/traverse/ListKTraverse.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/traverse/ListKTraverse.kt new file mode 100644 index 000000000..3896a61df --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/traverse/ListKTraverse.kt @@ -0,0 +1,82 @@ +package arrow.core.extensions.listk.traverse + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.extensions.ListKTraverse +import arrow.typeclasses.Applicative +import arrow.typeclasses.Monad +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val traverse_singleton: ListKTraverse = object : arrow.core.extensions.ListKTraverse {} + +@JvmName("traverse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with traverseEither or traverseValidated from arrow.core.*") +fun Kind.traverse(arg1: Applicative, arg2: Function1>): + Kind> = arrow.core.ListK.traverse().run { + this@traverse.traverse(arg1, arg2) as arrow.Kind> +} + +@JvmName("sequence") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with sequenceEither or sequenceValidated from arrow.core.*") +fun Kind>.sequence(arg1: Applicative): Kind> = + arrow.core.ListK.traverse().run { + this@sequence.sequence(arg1) as arrow.Kind> +} + +@JvmName("map") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated", ReplaceWith("map(arg1)")) +fun Kind.map(arg1: Function1): ListK = + arrow.core.ListK.traverse().run { + this@map.map(arg1) as arrow.core.ListK +} + +@JvmName("flatTraverse") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension kinded projected functions are deprecated. Replace with flatTraverseEither or flatTraverseValidated from arrow.core.*") +fun Kind.flatTraverse( + arg1: Monad, + arg2: Applicative, + arg3: Function1>> +): Kind> = arrow.core.ListK.traverse().run { + this@flatTraverse.flatTraverse(arg1, arg2, arg3) as arrow.Kind> +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Traverse typeclasses is deprecated. Use concrete methods on Iterable") +inline fun Companion.traverse(): ListKTraverse = traverse_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/unalign/ListKUnalign.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/unalign/ListKUnalign.kt new file mode 100644 index 000000000..4a8e62b41 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/unalign/ListKUnalign.kt @@ -0,0 +1,53 @@ +package arrow.core.extensions.listk.unalign + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.Ior +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKUnalign +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val unalign_singleton: ListKUnalign = object : arrow.core.extensions.ListKUnalign {} + +@JvmName("unalign") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.unalign()", "arrow.core.unalign")) +fun unalign(arg0: Kind>): Tuple2, Kind> = + arrow.core.ListK + .unalign() + .unalign(arg0) as arrow.core.Tuple2, + arrow.Kind> + +@JvmName("unalignWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("arg0.unalignWith(arg1)", "arrow.core.unalignWith")) +fun unalignWith(arg0: Kind, arg1: Function1>): + Tuple2, Kind> = arrow.core.ListK + .unalign() + .unalignWith(arg0, arg1) as arrow.core.Tuple2, + arrow.Kind> + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Unalign typeclasses is deprecated. Use concrete methods on Iterable") +inline fun Companion.unalign(): ListKUnalign = unalign_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/unzip/ListKUnzip.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/unzip/ListKUnzip.kt new file mode 100644 index 000000000..c37632638 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/unzip/ListKUnzip.kt @@ -0,0 +1,52 @@ +package arrow.core.extensions.listk.unzip + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKUnzip +import kotlin.Function1 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val unzip_singleton: ListKUnzip = object : arrow.core.extensions.ListKUnzip {} + +@JvmName("unzip") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("unzip()", "arrow.core.unzip")) +fun Kind>.unzip(): Tuple2, Kind> = + arrow.core.ListK.unzip().run { + this@unzip.unzip() as arrow.core.Tuple2, + arrow.Kind> +} + +@JvmName("unzipWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("unzipWith(arg1)", "arrow.core.unzipWith")) +fun Kind.unzipWith(arg1: Function1>): Tuple2, Kind> = arrow.core.ListK.unzip().run { + this@unzipWith.unzipWith(arg1) as arrow.core.Tuple2, + arrow.Kind> +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Unzip typeclasses is deprecated. Use concrete methods on Iterable") +inline fun Companion.unzip(): ListKUnzip = unzip_singleton diff --git a/arrow-core/src/main/kotlin/arrow/core/extensions/listk/zip/ListKZip.kt b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/zip/ListKZip.kt new file mode 100644 index 000000000..e3e6123d7 --- /dev/null +++ b/arrow-core/src/main/kotlin/arrow/core/extensions/listk/zip/ListKZip.kt @@ -0,0 +1,51 @@ +package arrow.core.extensions.listk.zip + +import arrow.Kind +import arrow.core.ForListK +import arrow.core.ListK +import arrow.core.ListK.Companion +import arrow.core.Tuple2 +import arrow.core.extensions.ListKZip +import kotlin.Function2 +import kotlin.PublishedApi +import kotlin.Suppress +import kotlin.jvm.JvmName + +/** + * cached extension + */ +@PublishedApi() +internal val zip_singleton: ListKZip = object : arrow.core.extensions.ListKZip {} + +@JvmName("zip") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("zip(arg1).map { it.toTuple2() }", "arrow.core.toTuple2")) +fun Kind.zip(arg1: Kind): ListK> = + arrow.core.ListK.zip().run { + this@zip.zip(arg1) as arrow.core.ListK> +} + +@JvmName("zipWith") +@Suppress( + "UNCHECKED_CAST", + "USELESS_CAST", + "EXTENSION_SHADOWED_BY_MEMBER", + "UNUSED_PARAMETER" +) +@Deprecated("@extension projected functions are deprecated", ReplaceWith("zip(arg1, arg2)")) +fun Kind.zipWith(arg1: Kind, arg2: Function2): ListK = + arrow.core.ListK.zip().run { + this@zipWith.zipWith(arg1, arg2) as arrow.core.ListK +} + +@Suppress( + "UNCHECKED_CAST", + "NOTHING_TO_INLINE" +) +@Deprecated("Zip typeclasses is deprecated. Use concrete methods on Iterable") +inline fun Companion.zip(): ListKZip = zip_singleton