From 6e1dc8fb44219442372d271798150e15c9c45e99 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 18 Nov 2022 16:36:17 +0100 Subject: [PATCH 01/11] Use the more common optics hierarchy also in Arrow --- .../commonMain/kotlin/arrow/optics/Copy.kt | 4 +- .../commonMain/kotlin/arrow/optics/Every.kt | 712 ++++++++---------- .../commonMain/kotlin/arrow/optics/Fold.kt | 12 +- .../commonMain/kotlin/arrow/optics/Getter.kt | 42 +- .../src/commonMain/kotlin/arrow/optics/Iso.kt | 3 +- .../commonMain/kotlin/arrow/optics/Lens.kt | 3 +- .../kotlin/arrow/optics/Optional.kt | 4 +- .../kotlin/arrow/optics/OptionalGetter.kt | 9 +- .../commonMain/kotlin/arrow/optics/Prism.kt | 2 +- .../commonMain/kotlin/arrow/optics/Setter.kt | 146 +++- .../kotlin/arrow/optics/Traversal.kt | 157 ++-- .../kotlin/arrow/optics/dsl/every.kt | 14 +- .../arrow/optics/typeclasses/FilterIndex.kt | 11 +- .../kotlin/arrow/optics/TestDomain.kt | 2 +- 14 files changed, 601 insertions(+), 520 deletions(-) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt index 87a21dfd257..3bdaae46d9b 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt @@ -15,7 +15,7 @@ public interface Copy { /** * Transforms the value of the element(s) pointed by the [Traversal]. */ - public infix fun Traversal.transform(f: (B) -> B) + public infix fun Setter.transform(f: (B) -> B) /** * Declares a block in which all optics are nested within @@ -49,7 +49,7 @@ private class CopyImpl(var current: A): Copy { override fun Setter.set(b: B) { current = this.set(current, b) } - override fun Traversal.transform(f: (B) -> B) { + override fun Setter.transform(f: (B) -> B) { current = this.modify(current, f) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt index 33b96bf40e7..4cfd8df8ed7 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt @@ -15,435 +15,345 @@ import arrow.core.foldMap import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic -public typealias Every = PEvery - -/** - * Composition of Fold and Traversal - * It combines their powers - */ -public interface PEvery : PTraversal, Fold, PSetter { +public object Every { + /** + * [Traversal] for [List] that focuses in each [A] of the source [List]. + */ + @JvmStatic + public fun list(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: List, map: (focus: A) -> A): List = + source.map(map) + + override fun foldMap(M: Monoid, source: List, map: (focus: A) -> R): R = + source.foldMap(M, map) + } /** - * Map each target to a type R and use a Monoid to fold the results + * [Traversal] for [Either] that has focus in each [Either.Right]. + * + * @receiver [Traversal.Companion] to make it statically available. + * @return [Traversal] with source [Either] and focus every [Either.Right] of the source. */ - override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R + @JvmStatic + public fun either(): Traversal, R> = + object : Traversal, R> { + override fun modify(source: Either, map: (focus: R) -> R): Either = + source.map(map) + + override fun foldMap(M: Monoid, source: Either, map: (focus: R) -> A): A = + source.foldMap(M, map) + } + + @JvmStatic + public fun map(): Traversal, V> = + object : Traversal, V> { + override fun modify(source: Map, map: (focus: V) -> V): Map = + source.mapValues { (_, v) -> map(v) } - override fun modify(source: S, map: (focus: A) -> B): T + override fun foldMap(M: Monoid, source: Map, map: (focus: V) -> R): R = + M.run { + source.foldLeft(empty()) { acc, (_, v) -> + acc.combine(map(v)) + } + } + } /** - * Compose a [PEvery] with a [PEvery] + * [Traversal] for [NonEmptyList] that has focus in each [A]. + * + * @receiver [PTraversal.Companion] to make it statically available. + * @return [Traversal] with source [NonEmptyList] and focus every [A] of the source. */ - public infix fun compose(other: PEvery): PEvery = - object : PEvery { - override fun foldMap(M: Monoid, source: S, map: (C) -> R): R = - this@PEvery.foldMap(M, source) { c -> other.foldMap(M, c, map) } + @JvmStatic + public fun nonEmptyList(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: NonEmptyList, map: (focus: A) -> A): NonEmptyList = + source.map(map) + + override fun foldMap(M: Monoid, source: NonEmptyList, map: (focus: A) -> R): R = + source.foldMap(M, map) + } - override fun modify(source: S, map: (focus: C) -> D): T = - this@PEvery.modify(source) { b -> other.modify(b, map) } + /** + * [Traversal] for [Option] that has focus in each [arrow.core.Some]. + * + * @receiver [PTraversal.Companion] to make it statically available. + * @return [Traversal] with source [Option] and focus in every [arrow.core.Some] of the source. + */ + @JvmStatic + public fun option(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Option, map: (focus: A) -> A): Option = + source.map(map) + + override fun foldMap(M: Monoid, source: Option, map: (focus: A) -> R): R = + source.foldMap(M, map) } - public operator fun plus(other: PEvery): PEvery = - this compose other - - public companion object { - public fun from(T: Traversal, F: Fold): Every = - object : Every { - override fun foldMap(M: Monoid, source: S, map: (A) -> R): R = F.foldMap(M, source, map) - override fun modify(source: S, map: (focus: A) -> A): S = T.modify(source, map) - } - - /** - * [Traversal] for [List] that focuses in each [A] of the source [List]. - */ - @JvmStatic - public fun list(): Every, A> = - object : Every, A> { - override fun modify(source: List, map: (focus: A) -> A): List = - source.map(map) - - override fun foldMap(M: Monoid, source: List, map: (focus: A) -> R): R = - source.foldMap(M, map) - } - - /** - * [Traversal] for [Either] that has focus in each [Either.Right]. - * - * @receiver [Traversal.Companion] to make it statically available. - * @return [Traversal] with source [Either] and focus every [Either.Right] of the source. - */ - @JvmStatic - public fun either(): Every, R> = - object : Every, R> { - override fun modify(source: Either, map: (focus: R) -> R): Either = - source.map(map) - - override fun foldMap(M: Monoid, source: Either, map: (focus: R) -> A): A = - source.foldMap(M, map) - } - - @JvmStatic - public fun map(): Every, V> = - object : Every, V> { - override fun modify(source: Map, map: (focus: V) -> V): Map = - source.mapValues { (_, v) -> map(v) } - - override fun foldMap(M: Monoid, source: Map, map: (focus: V) -> R): R = - M.run { - source.foldLeft(empty()) { acc, (_, v) -> - acc.combine(map(v)) - } - } - } - - /** - * [Traversal] for [NonEmptyList] that has focus in each [A]. - * - * @receiver [PTraversal.Companion] to make it statically available. - * @return [Traversal] with source [NonEmptyList] and focus every [A] of the source. - */ - @JvmStatic - public fun nonEmptyList(): Every, A> = - object : Every, A> { - override fun modify(source: NonEmptyList, map: (focus: A) -> A): NonEmptyList = - source.map(map) - - override fun foldMap(M: Monoid, source: NonEmptyList, map: (focus: A) -> R): R = - source.foldMap(M, map) - } - - /** - * [Traversal] for [Option] that has focus in each [arrow.core.Some]. - * - * @receiver [PTraversal.Companion] to make it statically available. - * @return [Traversal] with source [Option] and focus in every [arrow.core.Some] of the source. - */ - @JvmStatic - public fun option(): Every, A> = - object : Every, A> { - override fun modify(source: Option, map: (focus: A) -> A): Option = - source.map(map) - - override fun foldMap(M: Monoid, source: Option, map: (focus: A) -> R): R = - source.foldMap(M, map) - } - - @JvmStatic - public fun sequence(): Every, A> = - object : Every, A> { - override fun modify(source: Sequence, map: (focus: A) -> A): Sequence = - source.map(map) - - override fun foldMap(M: Monoid, source: Sequence, map: (focus: A) -> R): R = - M.run { - source.fold(empty()) { acc, a -> - acc.combine(map(a)) - } - } - } - - /** - * [Traversal] for [String] that focuses in each [Char] of the source [String]. - * - * @receiver [PTraversal.Companion] to make it statically available. - * @return [Traversal] with source [String] and foci every [Char] in the source. - */ - @JvmStatic - public fun string(): Every = - object : Every { - override fun modify(source: String, map: (focus: Char) -> Char): String = - source.map(map).joinToString(separator = "") - - override fun foldMap(M: Monoid, source: String, map: (focus: Char) -> R): R = - M.run { - source.fold(empty()) { acc, char -> acc.combine(map(char)) } - } - } - - /** - * [Traversal] to focus into the first and second value of a [Pair] - */ - @JvmStatic - public fun pair(): Every, A> = - object : Every, A> { - override fun modify(source: Pair, map: (focus: A) -> A): Pair = - Pair(map(source.first), map(source.second)) - - override fun foldMap(M: Monoid, source: Pair, map: (focus: A) -> R): R = - M.run { - map(source.first).combine(map(source.second)) - } - } - - /** - * [Traversal] to focus into the first, second and third value of a [Triple] - */ - @JvmStatic - public fun triple(): Every, A> = - object : Every, A> { - override fun modify(source: Triple, map: (focus: A) -> A): Triple = - Triple(map(source.first), map(source.second), map(source.third)) - - override fun foldMap(M: Monoid, source: Triple, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - } - } - - /** - * [Traversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4] - */ - @JvmStatic - public fun tuple4(): Every, A> = - object : Every, A> { - override fun modify(source: Tuple4, map: (focus: A) -> A): Tuple4 = - Tuple4(map(source.first), map(source.second), map(source.third), map(source.fourth)) - - override fun foldMap(M: Monoid, source: Tuple4, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - } - } - - /** - * [PTraversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5] - */ - @JvmStatic - public fun tuple5(): Every, A> = - object : Every, A> { - override fun modify(source: Tuple5, map: (focus: A) -> A): Tuple5 = - Tuple5(map(source.first), map(source.second), map(source.third), map(source.fourth), map(source.fifth)) - - override fun foldMap(M: Monoid, source: Tuple5, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - } - } - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6] - */ - @JvmStatic - public fun tuple6(): Every, A> = - object : Every, A> { - override fun modify(source: Tuple6, map: (focus: A) -> A): Tuple6 = - Tuple6( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth) - ) - - override fun foldMap(M: Monoid, source: Tuple6, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - .combine(map(source.sixth)) - } - } - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7] - */ - @JvmStatic - public fun tuple7(): Every, A> = - object : Every, A> { - override fun modify(source: Tuple7, map: (focus: A) -> A): Tuple7 = - Tuple7( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh) - ) - - override fun foldMap(M: Monoid, source: Tuple7, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - .combine(map(source.sixth)) - .combine(map(source.seventh)) - } - } - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8] - */ - @JvmStatic - public fun tuple8(): Every, A> = - object : Every, A> { - override fun modify( - source: Tuple8, - map: (focus: A) -> A - ): Tuple8 = - Tuple8( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh), - map(source.eighth) - ) - - override fun foldMap(M: Monoid, source: Tuple8, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - .combine(map(source.sixth)) - .combine(map(source.seventh)) - .combine(map(source.eighth)) - } - } - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9] - */ - @JvmStatic - public fun tuple9(): Every, A> = - object : Every, A> { - override fun modify( - source: Tuple9, - map: (focus: A) -> A - ): Tuple9 = - Tuple9( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh), - map(source.eighth), - map(source.ninth) - ) - - override fun foldMap(M: Monoid, source: Tuple9, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - .combine(map(source.sixth)) - .combine(map(source.seventh)) - .combine(map(source.eighth)) - .combine(map(source.ninth)) - } - } - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10] - */ - @JvmStatic - public fun tuple10(): Every, A> = - object : Every, A> { - override fun modify( - source: Tuple10, - map: (focus: A) -> A - ): Tuple10 = - Tuple10( - map(source.first), - map(source.second), - map(source.third), - map(source.fourth), - map(source.fifth), - map(source.sixth), - map(source.seventh), - map(source.eighth), - map(source.ninth), - map(source.tenth) - ) - - override fun foldMap(M: Monoid, source: Tuple10, map: (focus: A) -> R): R = - M.run { - map(source.first) - .combine(map(source.second)) - .combine(map(source.third)) - .combine(map(source.fourth)) - .combine(map(source.fifth)) - .combine(map(source.sixth)) - .combine(map(source.seventh)) - .combine(map(source.eighth)) - .combine(map(source.ninth)) - .combine(map(source.tenth)) + @JvmStatic + public fun sequence(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Sequence, map: (focus: A) -> A): Sequence = + source.map(map) + + override fun foldMap(M: Monoid, source: Sequence, map: (focus: A) -> R): R = + M.run { + source.fold(empty()) { acc, a -> + acc.combine(map(a)) } - } - } + } + } /** - * DSL to compose [Every] with a [Lens] for a structure [S] to see all its foci [A] + * [Traversal] for [String] that focuses in each [Char] of the source [String]. * - * @receiver [Lens] with a focus in [S] - * @return [Every] with a focus in [A] + * @receiver [PTraversal.Companion] to make it statically available. + * @return [Traversal] with source [String] and foci every [Char] in the source. */ - override val PLens.every: PEvery - get() = this@every.compose(this@PEvery) + @JvmStatic + public fun string(): Traversal = + object : Traversal { + override fun modify(source: String, map: (focus: Char) -> Char): String = + source.map(map).joinToString(separator = "") + + override fun foldMap(M: Monoid, source: String, map: (focus: Char) -> R): R = + M.run { + source.fold(empty()) { acc, char -> acc.combine(map(char)) } + } + } /** - * DSL to compose [Every] with a [Iso] for a structure [S] to see all its foci [A] - * - * @receiver [Iso] with a focus in [S] - * @return [Every] with a focus in [A] + * [Traversal] to focus into the first and second value of a [Pair] */ - override val PIso.every: PEvery - get() = this@every.compose(this@PEvery) + @JvmStatic + public fun pair(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Pair, map: (focus: A) -> A): Pair = + Pair(map(source.first), map(source.second)) + + override fun foldMap(M: Monoid, source: Pair, map: (focus: A) -> R): R = + M.run { + map(source.first).combine(map(source.second)) + } + } /** - * DSL to compose [Every] with a [Prism] for a structure [S] to see all its foci [A] - * - * @receiver [Prism] with a focus in [S] - * @return [Every] with a focus in [A] + * [Traversal] to focus into the first, second and third value of a [Triple] */ - override val PPrism.every: PEvery - get() = this.compose(this@PEvery) + @JvmStatic + public fun triple(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Triple, map: (focus: A) -> A): Triple = + Triple(map(source.first), map(source.second), map(source.third)) + + override fun foldMap(M: Monoid, source: Triple, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + } + } /** - * DSL to compose [Every] with a [Optional] for a structure [S] to see all its foci [A] - * - * @receiver [Optional] with a focus in [S] - * @return [Every] with a focus in [A] + * [Traversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4] */ - override val POptional.every: PEvery - get() = this.compose(this@PEvery) + @JvmStatic + public fun tuple4(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Tuple4, map: (focus: A) -> A): Tuple4 = + Tuple4(map(source.first), map(source.second), map(source.third), map(source.fourth)) + + override fun foldMap(M: Monoid, source: Tuple4, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + } + } /** - * DSL to compose [Every] with a [Setter] for a structure [S] to see all its foci [A] - * - * @receiver [Setter] with a focus in [S] - * @return [Setter] with a focus in [A] + * [PTraversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5] */ - override val PSetter.every: PSetter - get() = this.compose(this@PEvery) + @JvmStatic + public fun tuple5(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Tuple5, map: (focus: A) -> A): Tuple5 = + Tuple5(map(source.first), map(source.second), map(source.third), map(source.fourth), map(source.fifth)) + + override fun foldMap(M: Monoid, source: Tuple5, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + .combine(map(source.fifth)) + } + } /** - * DSL to compose [Every] with a [Traversal] for a structure [S] to see all its foci [A] - * - * @receiver [Traversal] with a focus in [S] - * @return [Traversal] with a focus in [A] + * [Traversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6] */ - override val PTraversal.every: PTraversal - get() = this.compose(this@PEvery) + @JvmStatic + public fun tuple6(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Tuple6, map: (focus: A) -> A): Tuple6 = + Tuple6( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth) + ) + + override fun foldMap(M: Monoid, source: Tuple6, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + .combine(map(source.fifth)) + .combine(map(source.sixth)) + } + } + + /** + * [Traversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7] + */ + @JvmStatic + public fun tuple7(): Traversal, A> = + object : Traversal, A> { + override fun modify(source: Tuple7, map: (focus: A) -> A): Tuple7 = + Tuple7( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh) + ) + + override fun foldMap(M: Monoid, source: Tuple7, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + .combine(map(source.fifth)) + .combine(map(source.sixth)) + .combine(map(source.seventh)) + } + } + + /** + * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8] + */ + @JvmStatic + public fun tuple8(): Traversal, A> = + object : Traversal, A> { + override fun modify( + source: Tuple8, + map: (focus: A) -> A + ): Tuple8 = + Tuple8( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh), + map(source.eighth) + ) + + override fun foldMap(M: Monoid, source: Tuple8, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + .combine(map(source.fifth)) + .combine(map(source.sixth)) + .combine(map(source.seventh)) + .combine(map(source.eighth)) + } + } + + /** + * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9] + */ + @JvmStatic + public fun tuple9(): Traversal, A> = + object : Traversal, A> { + override fun modify( + source: Tuple9, + map: (focus: A) -> A + ): Tuple9 = + Tuple9( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh), + map(source.eighth), + map(source.ninth) + ) + + override fun foldMap(M: Monoid, source: Tuple9, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + .combine(map(source.fifth)) + .combine(map(source.sixth)) + .combine(map(source.seventh)) + .combine(map(source.eighth)) + .combine(map(source.ninth)) + } + } + + /** + * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10] + */ + @JvmStatic + public fun tuple10(): Traversal, A> = + object : Traversal, A> { + override fun modify( + source: Tuple10, + map: (focus: A) -> A + ): Tuple10 = + Tuple10( + map(source.first), + map(source.second), + map(source.third), + map(source.fourth), + map(source.fifth), + map(source.sixth), + map(source.seventh), + map(source.eighth), + map(source.ninth), + map(source.tenth) + ) + + override fun foldMap(M: Monoid, source: Tuple10, map: (focus: A) -> R): R = + M.run { + map(source.first) + .combine(map(source.second)) + .combine(map(source.third)) + .combine(map(source.fourth)) + .combine(map(source.fifth)) + .combine(map(source.sixth)) + .combine(map(source.seventh)) + .combine(map(source.eighth)) + .combine(map(source.ninth)) + .combine(map(source.tenth)) + } + } + } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt index 446d625743b..8d94e3ddcc1 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt @@ -23,7 +23,7 @@ import kotlin.jvm.JvmStatic * @param S the source of a [Fold] * @param A the target of a [Fold] */ -public interface Fold { +public interface Fold { /** * Map each target to a type R and use a Monoid to fold the results @@ -91,14 +91,14 @@ public interface Fold { /** * Fold using the given [Monoid] instance. */ - public fun fold(M: Monoid, source: S): A = + public fun fold(M: Monoid<@UnsafeVariance A>, source: S): A = foldMap(M, source, ::identity) /** * Alias for fold. */ @Deprecated("use fold instead", ReplaceWith("fold(M, source)")) - public fun combineAll(M: Monoid, source: S): A = + public fun combineAll(M: Monoid<@UnsafeVariance A>, source: S): A = fold(M, source) /** @@ -136,7 +136,7 @@ public interface Fold { /** * Join two [Fold] with the same target */ - public infix fun choice(other: Fold): Fold, A> = + public infix fun choice(other: Fold): Fold, A> = object : Fold, A> { override fun foldMap(M: Monoid, source: Either, map: (focus: A) -> R): R = source.fold({ ac -> this@Fold.foldMap(M, ac, map) }, { c -> other.foldMap(M, c, map) }) @@ -165,13 +165,13 @@ public interface Fold { /** * Compose a [Fold] with a [Fold] */ - public infix fun compose(other: Fold): Fold = + public infix fun compose(other: Fold): Fold = object : Fold { override fun foldMap(M: Monoid, source: S, map: (focus: C) -> R): R = this@Fold.foldMap(M, source) { c -> other.foldMap(M, c, map) } } - public operator fun plus(other: Fold): Fold = + public operator fun plus(other: Fold): Fold = this compose other public companion object { diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt index eff9638ff56..b178100e881 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt @@ -3,9 +3,10 @@ package arrow.optics import arrow.core.Either import arrow.core.compose import arrow.core.identity -import arrow.core.right import arrow.typeclasses.Monoid +public typealias Getter = PGetter + /** * A [Getter] is an optic that allows to see into a structure and getting a focus. * @@ -15,65 +16,68 @@ import arrow.typeclasses.Monoid * @param S the source of a [Getter] * @param A the focus of a [Getter] */ -public fun interface Getter : Fold { +public fun interface PGetter : POptionalGetter { /** * Get the focus of a [Getter] */ public fun get(source: S): A + override fun getOrModify(source: S): Either = + Either.Right(get(source)) + override fun foldMap(M: Monoid, source: S, map: (A) -> R): R = map(get(source)) /** * Create a product of the [Getter] and a type [C] */ - public fun first(): Getter, Pair> = - Getter { (s, c) -> get(s) to c } + public override fun first(): PGetter, Pair, Pair> = + PGetter { (s, c) -> get(s) to c } /** * Create a product of type [C] and the [Getter] */ - public fun second(): Getter, Pair> = - Getter { (c, s) -> c to get(s) } + public override fun second(): PGetter, Pair, Pair> = + PGetter { (c, s) -> c to get(s) } /** * Create a sum of the [Getter] and type [C] */ - override fun left(): Getter, Either> = - Getter { sc -> sc.bimap(this::get, ::identity) } + override fun left(): PGetter, Either, Either> = + PGetter { sc -> sc.bimap(this::get, ::identity) } /** * Create a sum of type [C] and the [Getter] */ - override fun right(): Getter, Either> = - Getter { cs -> cs.map(this::get) } + override fun right(): PGetter, Either, Either> = + PGetter { cs -> cs.map(this::get) } /** * Join two [Getter] with the same focus */ - public infix fun choice(other: Getter): Getter, A> = - Getter { s -> s.fold(this::get, other::get) } + public infix fun choice(other: PGetter): PGetter, Either, A> = + PGetter { s -> s.fold(this::get, other::get) } /** * Pair two disjoint [Getter] */ - public infix fun split(other: Getter): Getter, Pair> = - Getter { (s, c) -> get(s) to other.get(c) } + public infix fun split(other: PGetter): PGetter, Pair, Pair> = + PGetter { (s, c) -> get(s) to other.get(c) } /** * Zip two [Getter] optics with the same source [S] */ - public infix fun zip(other: Getter): Getter> = - Getter { s -> get(s) to other.get(s) } + public infix fun zip(other: PGetter<@UnsafeVariance S, @UnsafeVariance T, C>): PGetter> = + PGetter { s -> get(s) to other.get(s) } /** * Compose a [Getter] with a [Getter] */ - public infix fun compose(other: Getter): Getter = - Getter(other::get compose this::get) + public infix fun compose(other: PGetter): PGetter = + PGetter(other::get compose this::get) - public operator fun plus(other: Getter): Getter = + public operator fun plus(other: PGetter): PGetter = this compose other public companion object { diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt index 007831bcd90..445a7d22b99 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt @@ -40,8 +40,7 @@ private val stringToList: Iso> = * @param A the focus of a [PIso] * @param B the modified target of a [PIso] */ -public interface PIso : PPrism, PLens, Getter, POptional, - PSetter, Fold, PTraversal, PEvery { +public interface PIso : PPrism, PLens { /** * Get the focus of a [PIso] diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt index fc6df414e64..b45855d4554 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt @@ -28,8 +28,7 @@ public typealias Lens = PLens * @param A the focus of a [PLens] * @param B the modified focus of a [PLens] */ -public interface PLens : Getter, POptional, PSetter, - PTraversal, PEvery { +public interface PLens : PGetter, POptional { override fun get(source: S): A diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index 556cef13ab3..5d2f263742c 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -60,7 +60,7 @@ public fun Optional(getOption: (source: S) -> Option, set: (source: S, * @param A the focus of a [POptional] * @param B the modified focus of a [POptional] */ -public interface POptional : PSetter, POptionalGetter, PTraversal, PEvery { +public interface POptional : POptionalGetter, PTraversal { /** * Get the modified source of a [POptional] @@ -130,7 +130,7 @@ public interface POptional : PSetter, POptionalGetter second(): POptional, Pair, Pair, Pair> = POptional( { (c, s) -> getOrModify(s).bimap({ c to it }, { c to it }) }, - { (c2, s), (c, b) -> setNullable(s, b)?.let { c to it } ?: c2 to set(s, b) } + { (c2, s), (c, b) -> setNullable(s, b)?.let { c to it } ?: (c2 to set(s, b)) } ) /** diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt index 0895012f327..c43315e5460 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt @@ -15,7 +15,6 @@ import kotlin.jvm.JvmStatic */ public typealias OptionalGetter = POptionalGetter -@Suppress("FunctionName") public fun OptionalGetter(getOption: (source: S) -> Option): OptionalGetter = POptionalGetter({ s -> getOption(s).toEither { s } }) @@ -26,7 +25,7 @@ public fun OptionalGetter(getOption: (source: S) -> Option): OptionalG * @param T the modified source of a [POptional] * @param A the focus of a [POptional] */ -public interface POptionalGetter: Fold { +public interface POptionalGetter: Fold { /** * Get the focus of an [OptionalGetter] or return the original value while allowing the type to change if it does not match */ @@ -44,7 +43,7 @@ public interface POptionalGetter: Fold { /** * Join two [POptionalGetter] with the same focus */ - public infix fun choice(other: POptionalGetter): POptionalGetter, Either, A> = + public infix fun choice(other: POptionalGetter): POptionalGetter, Either, A> = POptionalGetter( { sources -> sources.fold( @@ -77,7 +76,7 @@ public interface POptionalGetter: Fold { /** * Compose a [POptionalGetter] with a [POptionalGetter] */ - public infix fun compose(other: POptionalGetter): POptionalGetter = + public infix fun compose(other: POptionalGetter): POptionalGetter = POptionalGetter( { source -> getOrModify(source).flatMap { a -> @@ -86,7 +85,7 @@ public interface POptionalGetter: Fold { } ) - public operator fun plus(other: POptionalGetter): POptionalGetter = + public operator fun plus(other: POptionalGetter): POptionalGetter = this compose other public companion object { diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 46a0658c564..990e462d4b0 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -32,7 +32,7 @@ public typealias Prism = PPrism * @param A the focus of a [PPrism] * @param B the modified focus of a [PPrism] */ -public interface PPrism : POptional, PSetter, POptionalGetter, PTraversal, PEvery { +public interface PPrism : POptional { override fun getOrModify(source: S): Either diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt index 6c1bb1fc7dd..d74b95d8819 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt @@ -23,7 +23,7 @@ public typealias Setter = PSetter * @param A the focus of a [PSetter] * @param B the modified focus of a [PSetter] */ -public fun interface PSetter { +public fun interface PSetter { /** * Modify polymorphically the focus of a [PSetter] with a function [map]. @@ -45,7 +45,7 @@ public fun interface PSetter { /** * Join two [PSetter] with the same target */ - public infix fun choice(other: PSetter): PSetter, Either, A, B> = + public infix fun choice(other: PSetter): PSetter, Either, A, B> = PSetter { su, f -> su.bimap({ s -> modify(s, f) }, { u -> other.modify(u, f) }) } @@ -53,10 +53,10 @@ public fun interface PSetter { /** * Compose a [PSetter] with a [PSetter] */ - public infix fun compose(other: PSetter): PSetter = + public infix fun compose(other: PSetter): PSetter = PSetter { s, fb -> modify(s) { a -> other.modify(a, fb) } } - public operator fun plus(other: PSetter): PSetter = + public operator fun plus(other: PSetter): PSetter = this compose other public companion object { @@ -69,5 +69,143 @@ public fun interface PSetter { */ public fun codiagonal(): Setter, S> = Setter { aa, f -> aa.bimap(f, f) } + + /** + * [PTraversal] constructor from multiple getters of the same source. + */ + public operator fun invoke(get1: (S) -> A, get2: (S) -> A, set: (B, B, S) -> T): PSetter = + PSetter { s, f -> set(f(get1(s)), f(get2(s)), s) } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + set: (B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), s) } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + set: (B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s) } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + get5: (S) -> A, + set: (B, B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s) } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + get5: (S) -> A, + get6: (S) -> A, + set: (B, B, B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s) } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + get5: (S) -> A, + get6: (S) -> A, + get7: (S) -> A, + set: (B, B, B, B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s) } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + get5: (S) -> A, + get6: (S) -> A, + get7: (S) -> A, + get8: (S) -> A, + set: (B, B, B, B, B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> + set( + f(get1(s)), + f(get2(s)), + f(get3(s)), + f(get4(s)), + f(get5(s)), + f(get6(s)), + f(get7(s)), + f(get8(s)), + s + ) + } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + get5: (S) -> A, + get6: (S) -> A, + get7: (S) -> A, + get8: (S) -> A, + get9: (S) -> A, + set: (B, B, B, B, B, B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> + set( + f(get1(s)), + f(get2(s)), + f(get3(s)), + f(get4(s)), + f(get5(s)), + f(get6(s)), + f(get7(s)), + f(get8(s)), + f(get9(s)), + s + ) + } + + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + get3: (S) -> A, + get4: (S) -> A, + get5: (S) -> A, + get6: (S) -> A, + get7: (S) -> A, + get8: (S) -> A, + get9: (S) -> A, + get10: (S) -> A, + set: (B, B, B, B, B, B, B, B, B, B, S) -> T + ): PSetter = + PSetter { s, f -> + set( + f(get1(s)), + f(get2(s)), + f(get3(s)), + f(get4(s)), + f(get5(s)), + f(get6(s)), + f(get7(s)), + f(get8(s)), + f(get9(s)), + f(get10(s)), + s + ) + } + } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index 6a76c2542c9..10961e9f538 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -10,6 +10,7 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 +import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic /** @@ -29,33 +30,62 @@ public typealias Traversal = PTraversal * @param A the target of a [PTraversal] * @param B the modified target of a [PTraversal] */ -public fun interface PTraversal : PSetter { +public interface PTraversal : PSetter, Fold { + + /** + * Map each target to a type R and use a Monoid to fold the results + */ + override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R override fun modify(source: S, map: (focus: A) -> B): T public fun choice(other: PTraversal): PTraversal, Either, A, B> = - PTraversal { s, f -> - s.fold( - { a -> Either.Left(this@PTraversal.modify(a, f)) }, - { u -> Either.Right(other.modify(u, f)) } - ) + object : PTraversal, Either, A, B> { + override fun foldMap(M: Monoid, source: Either, map: (A) -> R): R = + source.fold( + { a -> this@PTraversal.foldMap(M, a, map) }, + { u -> other.foldMap(M, u, map) } + ) + + override fun modify(source: Either, map: (focus: A) -> B): Either = + source.fold( + { a -> Either.Left(this@PTraversal.modify(a, map)) }, + { u -> Either.Right(other.modify(u, map)) } + ) } /** * Compose a [PTraversal] with a [PTraversal] */ public infix fun compose(other: PTraversal): PTraversal = - PTraversal { s, f -> this@PTraversal.modify(s) { b -> other.modify(b, f) } } + object : PTraversal { + override fun foldMap(M: Monoid, source: S, map: (C) -> R): R = + this@PTraversal.foldMap(M, source) { c -> other.foldMap(M, c, map) } + + override fun modify(source: S, map: (focus: C) -> D): T = + this@PTraversal.modify(source) { b -> other.modify(b, map) } + } public operator fun plus(other: PTraversal): PTraversal = this compose other public companion object { + public fun id(): PTraversal = PIso.id() public fun codiagonal(): Traversal, S> = - Traversal { s, f -> s.bimap(f, f) } + object : Traversal, S> { + override fun foldMap(M: Monoid, source: Either, map: (focus: S) -> R): R = + source.fold( + { a -> map(a) }, + { u -> map(u) } + ) + + override fun modify(source: Either, map: (focus: S) -> S): Either = + source.bimap(map, map) + } + // Traversal { s, f -> s.bimap(f, f) } /** * [PTraversal] that points to nothing @@ -66,8 +96,17 @@ public fun interface PTraversal : PSetter { /** * [PTraversal] constructor from multiple getters of the same source. */ - public operator fun invoke(get1: (S) -> A, get2: (S) -> A, set: (B, B, S) -> T): PTraversal = - PTraversal { s, f -> set(f(get1(s)), f(get2(s)), s) } + public operator fun invoke( + get1: (S) -> A, + get2: (S) -> A, + set: (B, B, S) -> T + ): PTraversal = + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), s) + } public operator fun invoke( get1: (S) -> A, @@ -75,7 +114,12 @@ public fun interface PTraversal : PSetter { get3: (S) -> A, set: (B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), s) } + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), s) + } public operator fun invoke( get1: (S) -> A, @@ -84,7 +128,12 @@ public fun interface PTraversal : PSetter { get4: (S) -> A, set: (B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s) } + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s) + } public operator fun invoke( get1: (S) -> A, @@ -94,7 +143,12 @@ public fun interface PTraversal : PSetter { get5: (S) -> A, set: (B, B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s) } + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s) + } public operator fun invoke( get1: (S) -> A, @@ -105,7 +159,12 @@ public fun interface PTraversal : PSetter { get6: (S) -> A, set: (B, B, B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s) } + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s) + } public operator fun invoke( get1: (S) -> A, @@ -117,7 +176,12 @@ public fun interface PTraversal : PSetter { get7: (S) -> A, set: (B, B, B, B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s) } + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s) + } public operator fun invoke( get1: (S) -> A, @@ -130,18 +194,11 @@ public fun interface PTraversal : PSetter { get8: (S) -> A, set: (B, B, B, B, B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> - set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - s - ) + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), s) } public operator fun invoke( @@ -156,19 +213,11 @@ public fun interface PTraversal : PSetter { get9: (S) -> A, set: (B, B, B, B, B, B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> - set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - f(get9(s)), - s - ) + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), s) } public operator fun invoke( @@ -184,20 +233,11 @@ public fun interface PTraversal : PSetter { get10: (S) -> A, set: (B, B, B, B, B, B, B, B, B, B, S) -> T ): PTraversal = - PTraversal { s, f -> - set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - f(get9(s)), - f(get10(s)), - s - ) + object : PTraversal { + override fun foldMap(M: Monoid, s: S, f: (focus: A) -> R): R = + M.fold(listOf(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), f(get10(s)))) + override fun modify(s: S, f: (focus: A) -> B): T = + set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), f(get8(s)), f(get9(s)), f(get10(s)), s) } /** @@ -514,13 +554,4 @@ public fun interface PTraversal : PSetter { get() = this.compose(this@PTraversal) - /** - * DSL to compose [Traversal] with a [PEvery] for a structure [S] to see all its foci [A] - * - * @receiver [PEvery] with a focus in [S] - * @return [PEvery] with a focus in [A] - */ - public val PEvery.every: PTraversal - get() = - this.compose(this@PTraversal) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt index 3816731e952..eeda5c26ffe 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt @@ -16,7 +16,7 @@ import arrow.optics.Traversal * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Traversal] with a focus in [A] */ -public fun Lens.every(TR: Every): Every = this.compose(TR) +public fun Lens.every(TR: Traversal): Traversal = this.compose(TR) /** * DSL to compose [Traversal] with an [Iso] for a structure [S] to see all its foci [A] @@ -25,7 +25,7 @@ public fun Lens.every(TR: Every): Every = this.compo * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Traversal] with a focus in [A] */ -public fun Iso.every(TR: Every): Every = this.compose(TR) +public fun Iso.every(TR: Traversal): Traversal = this.compose(TR) /** * DSL to compose [Traversal] with a [Prism] for a structure [S] to see all its foci [A] @@ -34,7 +34,7 @@ public fun Iso.every(TR: Every): Every = this.compos * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Traversal] with a focus in [A] */ -public fun Prism.every(TR: Every): Every = this.compose(TR) +public fun Prism.every(TR: Traversal): Traversal = this.compose(TR) /** * DSL to compose [Traversal] with an [Optional] for a structure [S] to see all its foci [A] @@ -43,7 +43,7 @@ public fun Prism.every(TR: Every): Every = this.comp * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Traversal] with a focus in [A] */ -public fun Optional.every(TR: Every): Every = this.compose(TR) +public fun Optional.every(TR: Traversal): Traversal = this.compose(TR) /** * DSL to compose [Traversal] with a [Setter] for a structure [S] to see all its foci [A] @@ -52,7 +52,7 @@ public fun Optional.every(TR: Every): Every = this.c * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Setter] with a focus in [A] */ -public fun Setter.every(TR: Every): Setter = this.compose(TR) +public fun Setter.every(TR: Traversal): Setter = this.compose(TR) /** * DSL to compose [Traversal] with a [Traversal] for a structure [S] to see all its foci [A] @@ -61,7 +61,7 @@ public fun Setter.every(TR: Every): Setter = this.co * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Traversal] with a focus in [A] */ -public fun Traversal.every(TR: Every): Traversal = this.compose(TR) +public fun Traversal.every(TR: Traversal): Traversal = this.compose(TR) /** * DSL to compose [Traversal] with a [Fold] for a structure [S] to see all its foci [A] @@ -70,4 +70,4 @@ public fun Traversal.every(TR: Every): Traversal = t * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Fold] with a focus in [A] */ -public fun Fold.every(TR: Every): Fold = this.compose(TR) +public fun Fold.every(TR: Traversal): Fold = this.compose(TR) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt index d648fc91dd1..1f228612a88 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt @@ -5,6 +5,7 @@ import arrow.core.Predicate import arrow.core.toNonEmptyListOrNull import arrow.optics.Every import arrow.optics.Iso +import arrow.optics.Traversal import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic @@ -20,7 +21,7 @@ public fun interface FilterIndex { /** * Filter the foci [A] of a [Every] with the predicate [p]. */ - public fun filter(p: Predicate): Every + public fun filter(p: Predicate): Traversal public companion object { @@ -36,7 +37,7 @@ public fun interface FilterIndex { @JvmStatic public fun list(): FilterIndex, Int, A> = FilterIndex { p -> - object : Every, A> { + object : Traversal, A> { override fun foldMap(M: Monoid, source: List, map: (A) -> R): R = M.run { source.foldIndexed(empty()) { index, acc, a -> if (p(index)) acc.combine(map(a)) else acc } } @@ -49,7 +50,7 @@ public fun interface FilterIndex { @JvmStatic public fun map(): FilterIndex, K, V> = FilterIndex { p -> - object : Every, V> { + object : Traversal, V> { override fun foldMap(M: Monoid, source: Map, map: (V) -> R): R = M.run { source.entries.fold(empty()) { acc, (k, v) -> if (p(k)) acc.combine(map(v)) else acc @@ -67,7 +68,7 @@ public fun interface FilterIndex { @JvmStatic public fun nonEmptyList(): FilterIndex, Int, A> = FilterIndex { p -> - object : Every, A> { + object : Traversal, A> { override fun foldMap(M: Monoid, source: NonEmptyList, map: (A) -> R): R = M.run { source.foldIndexed(empty()) { index, acc, r -> if (p(index)) acc.combine(map(r)) else acc @@ -83,7 +84,7 @@ public fun interface FilterIndex { @JvmStatic public fun sequence(): FilterIndex, Int, A> = FilterIndex { p -> - object : Every, A> { + object : Traversal, A> { override fun foldMap(M: Monoid, source: Sequence, map: (A) -> R): R = M.run { source.foldIndexed(empty()) { index, acc, a -> if (p(index)) acc.combine(map(a)) else acc diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt index 1068b9624c4..9bf599d1472 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt @@ -71,7 +71,7 @@ internal data class IncompleteUser(val token: Token?) internal fun Arb.Companion.incompleteUser(): Arb = Arb.constant(IncompleteUser(null)) -internal fun Getter.Companion.token(): Getter = +internal fun PGetter.Companion.token(): Getter = Getter { it.value } internal fun PLens.Companion.user(): Lens = Lens( From 1510b07920c9eaa77cb1e4064db81dfe9fecff32 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 18 Nov 2022 18:15:50 +0100 Subject: [PATCH 02/11] Update API --- .../optics/arrow-optics/api/arrow-optics.api | 338 ++++++++---------- 1 file changed, 145 insertions(+), 193 deletions(-) diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index 970a6993266..dc3ae26f8d2 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -1,7 +1,7 @@ public abstract interface class arrow/optics/Copy { public abstract fun inside (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)V public abstract fun set (Larrow/optics/PSetter;Ljava/lang/Object;)V - public abstract fun transform (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)V + public abstract fun transform (Larrow/optics/PSetter;Lkotlin/jvm/functions/Function1;)V } public final class arrow/optics/Copy$DefaultImpls { @@ -12,6 +12,26 @@ public final class arrow/optics/CopyKt { public static final fun copy (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } +public final class arrow/optics/Every { + public static final field INSTANCE Larrow/optics/Every; + public static final fun either ()Larrow/optics/PTraversal; + public static final fun list ()Larrow/optics/PTraversal; + public static final fun map ()Larrow/optics/PTraversal; + public static final fun nonEmptyList ()Larrow/optics/PTraversal; + public static final fun option ()Larrow/optics/PTraversal; + public static final fun pair ()Larrow/optics/PTraversal; + public static final fun sequence ()Larrow/optics/PTraversal; + public static final fun string ()Larrow/optics/PTraversal; + public static final fun triple ()Larrow/optics/PTraversal; + public static final fun tuple10 ()Larrow/optics/PTraversal; + public static final fun tuple4 ()Larrow/optics/PTraversal; + public static final fun tuple5 ()Larrow/optics/PTraversal; + public static final fun tuple6 ()Larrow/optics/PTraversal; + public static final fun tuple7 ()Larrow/optics/PTraversal; + public static final fun tuple8 ()Larrow/optics/PTraversal; + public static final fun tuple9 ()Larrow/optics/PTraversal; +} + public abstract interface class arrow/optics/Fold { public static final field Companion Larrow/optics/Fold$Companion; public abstract fun all (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z @@ -95,54 +115,6 @@ public final class arrow/optics/Fold$DefaultImpls { public static fun size (Larrow/optics/Fold;Ljava/lang/Object;)I } -public abstract interface class arrow/optics/Getter : arrow/optics/Fold { - public static final field Companion Larrow/optics/Getter$Companion; - public abstract fun choice (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun compose (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun first ()Larrow/optics/Getter; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun left ()Larrow/optics/Getter; - public abstract fun plus (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun right ()Larrow/optics/Getter; - public abstract fun second ()Larrow/optics/Getter; - public abstract fun split (Larrow/optics/Getter;)Larrow/optics/Getter; - public abstract fun zip (Larrow/optics/Getter;)Larrow/optics/Getter; -} - -public final class arrow/optics/Getter$Companion { - public final fun codiagonal ()Larrow/optics/Getter; - public final fun id ()Larrow/optics/Getter; -} - -public final class arrow/optics/Getter$DefaultImpls { - public static fun all (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/Getter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun combineAll (Larrow/optics/Getter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/Getter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun exists (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun firstOrNull (Larrow/optics/Getter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/Getter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/Getter;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/Getter;Ljava/lang/Object;)Ljava/util/List; - public static fun isEmpty (Larrow/optics/Getter;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/Getter;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/Getter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun plus (Larrow/optics/Getter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun right (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun second (Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun size (Larrow/optics/Getter;Ljava/lang/Object;)I - public static fun split (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun zip (Larrow/optics/Getter;Larrow/optics/Getter;)Larrow/optics/Getter; -} - public final class arrow/optics/ListKt { public static final fun cons (Ljava/lang/Object;Ljava/util/List;)Ljava/util/List; public static final fun get (Larrow/optics/PLens;I)Larrow/optics/POptional; @@ -162,94 +134,61 @@ public final class arrow/optics/OptionalKt { public static final fun Optional (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; } -public abstract interface class arrow/optics/PEvery : arrow/optics/Fold, arrow/optics/PSetter, arrow/optics/PTraversal { - public static final field Companion Larrow/optics/PEvery$Companion; - public abstract fun compose (Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun either ()Larrow/optics/PEvery; +public abstract interface class arrow/optics/PGetter : arrow/optics/POptionalGetter { + public static final field Companion Larrow/optics/PGetter$Companion; + public abstract fun choice (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public abstract fun compose (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public abstract fun first ()Larrow/optics/PGetter; public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getEvery (Larrow/optics/PIso;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/PLens;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/POptional;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/PPrism;)Larrow/optics/PEvery; - public abstract fun getEvery (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun getEvery (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun list ()Larrow/optics/PEvery; - public static fun map ()Larrow/optics/PEvery; - public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun nonEmptyList ()Larrow/optics/PEvery; - public static fun option ()Larrow/optics/PEvery; - public static fun pair ()Larrow/optics/PEvery; - public abstract fun plus (Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun sequence ()Larrow/optics/PEvery; - public static fun string ()Larrow/optics/PEvery; - public static fun triple ()Larrow/optics/PEvery; - public static fun tuple10 ()Larrow/optics/PEvery; - public static fun tuple4 ()Larrow/optics/PEvery; - public static fun tuple5 ()Larrow/optics/PEvery; - public static fun tuple6 ()Larrow/optics/PEvery; - public static fun tuple7 ()Larrow/optics/PEvery; - public static fun tuple8 ()Larrow/optics/PEvery; - public static fun tuple9 ()Larrow/optics/PEvery; -} - -public final class arrow/optics/PEvery$Companion { - public final fun either ()Larrow/optics/PEvery; - public final fun from (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/PEvery; - public final fun list ()Larrow/optics/PEvery; - public final fun map ()Larrow/optics/PEvery; - public final fun nonEmptyList ()Larrow/optics/PEvery; - public final fun option ()Larrow/optics/PEvery; - public final fun pair ()Larrow/optics/PEvery; - public final fun sequence ()Larrow/optics/PEvery; - public final fun string ()Larrow/optics/PEvery; - public final fun triple ()Larrow/optics/PEvery; - public final fun tuple10 ()Larrow/optics/PEvery; - public final fun tuple4 ()Larrow/optics/PEvery; - public final fun tuple5 ()Larrow/optics/PEvery; - public final fun tuple6 ()Larrow/optics/PEvery; - public final fun tuple7 ()Larrow/optics/PEvery; - public final fun tuple8 ()Larrow/optics/PEvery; - public final fun tuple9 ()Larrow/optics/PEvery; -} - -public final class arrow/optics/PEvery$DefaultImpls { - public static fun all (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PEvery;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun choice (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/PEvery;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun compose (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun exists (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun firstOrNull (Larrow/optics/PEvery;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PEvery;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/PEvery;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PPrism;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun getEvery (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun isEmpty (Larrow/optics/PEvery;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/PEvery;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/PEvery;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PEvery;)Larrow/optics/Fold; - public static fun lift (Larrow/optics/PEvery;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun plus (Larrow/optics/PEvery;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/PEvery;)Larrow/optics/Fold; - public static fun set (Larrow/optics/PEvery;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun size (Larrow/optics/PEvery;Ljava/lang/Object;)I -} - -public abstract interface class arrow/optics/PIso : arrow/optics/Fold, arrow/optics/Getter, arrow/optics/PEvery, arrow/optics/PLens, arrow/optics/POptional, arrow/optics/PPrism, arrow/optics/PSetter, arrow/optics/PTraversal { + public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; + public abstract fun left ()Larrow/optics/PGetter; + public abstract fun plus (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public abstract fun right ()Larrow/optics/PGetter; + public abstract fun second ()Larrow/optics/PGetter; + public abstract fun split (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public abstract fun zip (Larrow/optics/PGetter;)Larrow/optics/PGetter; +} + +public final class arrow/optics/PGetter$Companion { + public final fun codiagonal ()Larrow/optics/PGetter; + public final fun id ()Larrow/optics/PGetter; +} + +public final class arrow/optics/PGetter$DefaultImpls { + public static fun all (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun any (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun choice (Larrow/optics/PGetter;Larrow/optics/Fold;)Larrow/optics/Fold; + public static fun choice (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun choice (Larrow/optics/PGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; + public static fun combineAll (Larrow/optics/PGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; + public static fun compose (Larrow/optics/PGetter;Larrow/optics/Fold;)Larrow/optics/Fold; + public static fun compose (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun compose (Larrow/optics/PGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; + public static fun exists (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun findOrNull (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun first (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun firstOrNull (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/lang/Object; + public static fun fold (Larrow/optics/PGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; + public static fun foldMap (Larrow/optics/PGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun getAll (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/util/List; + public static fun getOrModify (Larrow/optics/PGetter;Ljava/lang/Object;)Larrow/core/Either; + public static fun getOrNull (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/lang/Object; + public static fun isEmpty (Larrow/optics/PGetter;Ljava/lang/Object;)Z + public static fun isNotEmpty (Larrow/optics/PGetter;Ljava/lang/Object;)Z + public static fun lastOrNull (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/lang/Object; + public static fun left (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun plus (Larrow/optics/PGetter;Larrow/optics/Fold;)Larrow/optics/Fold; + public static fun plus (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun plus (Larrow/optics/PGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; + public static fun right (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun second (Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun size (Larrow/optics/PGetter;Ljava/lang/Object;)I + public static fun split (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; + public static fun zip (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; +} + +public abstract interface class arrow/optics/PIso : arrow/optics/PLens, arrow/optics/PPrism { public static final field Companion Larrow/optics/PIso$Companion; public abstract fun compose (Larrow/optics/PIso;)Larrow/optics/PIso; public static fun eitherToPValidated ()Larrow/optics/PIso; @@ -305,7 +244,7 @@ public final class arrow/optics/PIso$DefaultImpls { public static fun all (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun choice (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; + public static fun choice (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun choice (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun choice (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun choice (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; @@ -313,8 +252,7 @@ public final class arrow/optics/PIso$DefaultImpls { public static fun choice (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun compose (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PEvery; + public static fun compose (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun compose (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; public static fun compose (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun compose (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; @@ -329,11 +267,10 @@ public final class arrow/optics/PIso$DefaultImpls { public static fun fold (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PEvery; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrModify (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/core/Either; @@ -347,8 +284,7 @@ public final class arrow/optics/PIso$DefaultImpls { public static fun modify (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun plus (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PEvery; + public static fun plus (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun plus (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; public static fun plus (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun plus (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; @@ -363,13 +299,13 @@ public final class arrow/optics/PIso$DefaultImpls { public static fun set (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun setNullable (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/PIso;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; + public static fun split (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun split (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; public static fun split (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun zip (Larrow/optics/PIso;Larrow/optics/Getter;)Larrow/optics/Getter; + public static fun zip (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; } -public abstract interface class arrow/optics/PLens : arrow/optics/Getter, arrow/optics/PEvery, arrow/optics/POptional, arrow/optics/PSetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/PLens : arrow/optics/PGetter, arrow/optics/POptional { public static final field Companion Larrow/optics/PLens$Companion; public abstract fun choice (Larrow/optics/PLens;)Larrow/optics/PLens; public abstract fun compose (Larrow/optics/PLens;)Larrow/optics/PLens; @@ -417,7 +353,7 @@ public final class arrow/optics/PLens$DefaultImpls { public static fun all (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun choice (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; + public static fun choice (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun choice (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun choice (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun choice (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; @@ -425,8 +361,7 @@ public final class arrow/optics/PLens$DefaultImpls { public static fun choice (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun compose (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun compose (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PEvery; + public static fun compose (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun compose (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun compose (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun compose (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; @@ -439,11 +374,10 @@ public final class arrow/optics/PLens$DefaultImpls { public static fun fold (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PPrism;)Larrow/optics/PEvery; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PIso;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrModify (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/core/Either; @@ -451,28 +385,27 @@ public final class arrow/optics/PLens$DefaultImpls { public static fun isEmpty (Larrow/optics/PLens;Ljava/lang/Object;)Z public static fun isNotEmpty (Larrow/optics/PLens;Ljava/lang/Object;)Z public static fun lastOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PLens;)Larrow/optics/Getter; + public static fun left (Larrow/optics/PLens;)Larrow/optics/PGetter; public static fun lift (Larrow/optics/PLens;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun plus (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; - public static fun plus (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PEvery; + public static fun plus (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun plus (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun plus (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun plus (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun plus (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/PLens;)Larrow/optics/Getter; + public static fun right (Larrow/optics/PLens;)Larrow/optics/PGetter; public static fun second (Larrow/optics/PLens;)Larrow/optics/PLens; public static fun setNullable (Larrow/optics/PLens;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/PLens;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; + public static fun split (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun split (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun zip (Larrow/optics/PLens;Larrow/optics/Getter;)Larrow/optics/Getter; + public static fun zip (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; } -public abstract interface class arrow/optics/POptional : arrow/optics/PEvery, arrow/optics/POptionalGetter, arrow/optics/PSetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/POptional : arrow/optics/POptionalGetter, arrow/optics/PTraversal { public static final field Companion Larrow/optics/POptional$Companion; public abstract fun choice (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun compose (Larrow/optics/POptional;)Larrow/optics/POptional; @@ -510,7 +443,6 @@ public final class arrow/optics/POptional$DefaultImpls { public static fun choice (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun compose (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun compose (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun compose (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun compose (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; @@ -522,11 +454,10 @@ public final class arrow/optics/POptional$DefaultImpls { public static fun fold (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PPrism;)Larrow/optics/PEvery; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PIso;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object; @@ -538,7 +469,6 @@ public final class arrow/optics/POptional$DefaultImpls { public static fun modify (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun plus (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun plus (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun plus (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun plus (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; @@ -595,7 +525,7 @@ public final class arrow/optics/POptionalGetter$DefaultImpls { public static fun size (Larrow/optics/POptionalGetter;Ljava/lang/Object;)I } -public abstract interface class arrow/optics/PPrism : arrow/optics/PEvery, arrow/optics/POptional, arrow/optics/POptionalGetter, arrow/optics/PSetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/PPrism : arrow/optics/POptional { public static final field Companion Larrow/optics/PPrism$Companion; public abstract fun compose (Larrow/optics/PPrism;)Larrow/optics/PPrism; public abstract fun first ()Larrow/optics/PPrism; @@ -634,7 +564,6 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun choice (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun compose (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun compose (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism; @@ -647,11 +576,10 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun fold (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PIso;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PLens;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/PEvery; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PEvery; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PIso;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PLens;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/PTraversal; + public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrNull (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/lang/Object; @@ -664,7 +592,6 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun modify (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun plus (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PEvery; public static fun plus (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; public static fun plus (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun plus (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism; @@ -690,6 +617,15 @@ public abstract interface class arrow/optics/PSetter { public final class arrow/optics/PSetter$Companion { public final fun codiagonal ()Larrow/optics/PSetter; public final fun id ()Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function10;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function11;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function9;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function8;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function7;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function6;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;)Larrow/optics/PSetter; + public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Larrow/optics/PSetter; } public final class arrow/optics/PSetter$DefaultImpls { @@ -700,12 +636,12 @@ public final class arrow/optics/PSetter$DefaultImpls { public static fun set (Larrow/optics/PSetter;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; } -public abstract interface class arrow/optics/PTraversal : arrow/optics/PSetter { +public abstract interface class arrow/optics/PTraversal : arrow/optics/Fold, arrow/optics/PSetter { public static final field Companion Larrow/optics/PTraversal$Companion; public abstract fun choice (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public abstract fun compose (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun either ()Larrow/optics/PTraversal; - public abstract fun getEvery (Larrow/optics/PEvery;)Larrow/optics/PTraversal; + public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun getEvery (Larrow/optics/PIso;)Larrow/optics/PTraversal; public abstract fun getEvery (Larrow/optics/PLens;)Larrow/optics/PTraversal; public abstract fun getEvery (Larrow/optics/POptional;)Larrow/optics/PTraversal; @@ -781,21 +717,37 @@ public final class arrow/optics/PTraversal$Companion { } public final class arrow/optics/PTraversal$DefaultImpls { + public static fun all (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun any (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun choice (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun combineAll (Larrow/optics/PTraversal;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; + public static fun compose (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PEvery;)Larrow/optics/PTraversal; + public static fun exists (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public static fun findOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun firstOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object; + public static fun fold (Larrow/optics/PTraversal;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; + public static fun getAll (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/util/List; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PIso;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PLens;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/POptional;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PPrism;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun isEmpty (Larrow/optics/PTraversal;Ljava/lang/Object;)Z + public static fun isNotEmpty (Larrow/optics/PTraversal;Ljava/lang/Object;)Z + public static fun lastOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object; + public static fun left (Larrow/optics/PTraversal;)Larrow/optics/Fold; public static fun lift (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; + public static fun plus (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun plus (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static fun right (Larrow/optics/PTraversal;)Larrow/optics/Fold; public static fun set (Larrow/optics/PTraversal;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public static fun size (Larrow/optics/PTraversal;Ljava/lang/Object;)I } public final class arrow/optics/PrismKt { @@ -804,7 +756,7 @@ public final class arrow/optics/PrismKt { public final class arrow/optics/dsl/AtKt { public static final fun at (Larrow/optics/Fold;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/Fold; - public static final fun at (Larrow/optics/Getter;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/Getter; + public static final fun at (Larrow/optics/PGetter;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PGetter; public static final fun at (Larrow/optics/PIso;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PLens; public static final fun at (Larrow/optics/PLens;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PLens; public static final fun at (Larrow/optics/POptional;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/POptional; @@ -814,13 +766,13 @@ public final class arrow/optics/dsl/AtKt { } public final class arrow/optics/dsl/EveryKt { - public static final fun every (Larrow/optics/Fold;Larrow/optics/PEvery;)Larrow/optics/Fold; - public static final fun every (Larrow/optics/PIso;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/PLens;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/POptional;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/PPrism;Larrow/optics/PEvery;)Larrow/optics/PEvery; - public static final fun every (Larrow/optics/PSetter;Larrow/optics/PEvery;)Larrow/optics/PSetter; - public static final fun every (Larrow/optics/PTraversal;Larrow/optics/PEvery;)Larrow/optics/PTraversal; + public static final fun every (Larrow/optics/Fold;Larrow/optics/PTraversal;)Larrow/optics/Fold; + public static final fun every (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static final fun every (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static final fun every (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static final fun every (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public static final fun every (Larrow/optics/PSetter;Larrow/optics/PTraversal;)Larrow/optics/PSetter; + public static final fun every (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; } public final class arrow/optics/dsl/IndexKt { @@ -846,7 +798,7 @@ public final class arrow/optics/dsl/OptionKt { public abstract interface class arrow/optics/typeclasses/At { public static final field Companion Larrow/optics/typeclasses/At$Companion; public abstract fun at (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun at (Larrow/optics/Getter;Ljava/lang/Object;)Larrow/optics/Getter; + public abstract fun at (Larrow/optics/PGetter;Ljava/lang/Object;)Larrow/optics/PGetter; public abstract fun at (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/PLens; public abstract fun at (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens; public abstract fun at (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; @@ -866,7 +818,7 @@ public final class arrow/optics/typeclasses/At$Companion { public final class arrow/optics/typeclasses/At$DefaultImpls { public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/Getter;Ljava/lang/Object;)Larrow/optics/Getter; + public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PGetter;Ljava/lang/Object;)Larrow/optics/PGetter; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/PLens; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; @@ -907,7 +859,7 @@ public final class arrow/optics/typeclasses/Cons$DefaultImpls { public abstract interface class arrow/optics/typeclasses/FilterIndex { public static final field Companion Larrow/optics/typeclasses/FilterIndex$Companion; - public abstract fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/PEvery; + public abstract fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/PTraversal; public static fun list ()Larrow/optics/typeclasses/FilterIndex; public static fun map ()Larrow/optics/typeclasses/FilterIndex; public static fun nonEmptyList ()Larrow/optics/typeclasses/FilterIndex; From 9f3e1b55255414e431fe8798cb622eadc76ef446 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 18 Nov 2022 19:26:31 +0100 Subject: [PATCH 03/11] Update optics-reflect module --- .../arrow-optics-reflect/api/arrow-optics-reflect.api | 6 +++--- .../src/main/kotlin/arrow/optics/Reflection.kt | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api b/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api index d5a82f85bcd..4a3b3c3ea11 100644 --- a/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api +++ b/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api @@ -1,10 +1,10 @@ public final class arrow/optics/ReflectionKt { - public static final fun getEvery (Lkotlin/reflect/KProperty1;)Larrow/optics/PEvery; + public static final fun getEvery (Lkotlin/reflect/KProperty1;)Larrow/optics/PTraversal; public static final fun getIter (Lkotlin/jvm/functions/Function1;)Larrow/optics/Fold; public static final fun getLens (Lkotlin/reflect/KProperty1;)Larrow/optics/PLens; - public static final fun getOgetter (Lkotlin/jvm/functions/Function1;)Larrow/optics/Getter; + public static final fun getOgetter (Lkotlin/jvm/functions/Function1;)Larrow/optics/PGetter; public static final fun getOptional (Lkotlin/reflect/KProperty1;)Larrow/optics/POptional; - public static final fun getValues (Lkotlin/reflect/KProperty1;)Larrow/optics/PEvery; + public static final fun getValues (Lkotlin/reflect/KProperty1;)Larrow/optics/PTraversal; public static final fun instance (Lkotlin/reflect/KClass;)Larrow/optics/PPrism; } diff --git a/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt b/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt index 4e34bc43880..e73e4c22fc7 100644 --- a/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt +++ b/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt @@ -46,10 +46,10 @@ public val KProperty1.optional: Optional public val ((S) -> Iterable).iter: Fold get() = ogetter compose Fold.iterable() -public val KProperty1>.every: Every +public val KProperty1>.every: Traversal get() = lens compose Every.list() -public val KProperty1>.values: Every +public val KProperty1>.values: Traversal get() = lens compose Every.map() private fun clone(prop: KProperty1, value: S, newField: A): S { From 5995975469d75e75b130a2983e38eb8481853b07 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 18 Nov 2022 20:17:19 +0100 Subject: [PATCH 04/11] Fix problem with tests --- arrow-libs/core/arrow-atomic/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/arrow-libs/core/arrow-atomic/build.gradle.kts b/arrow-libs/core/arrow-atomic/build.gradle.kts index 5ef68dd39a6..c44f9542bc7 100644 --- a/arrow-libs/core/arrow-atomic/build.gradle.kts +++ b/arrow-libs/core/arrow-atomic/build.gradle.kts @@ -34,6 +34,7 @@ kotlin { jvmTest { dependencies { + runtimeOnly(libs.kotest.runnerJUnit5) implementation(projects.arrowFxCoroutines) } } From b6e0cc8ecdb699e657600c8c71ea1a7dd44eecf2 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Fri, 18 Nov 2022 21:05:45 +0100 Subject: [PATCH 05/11] Do not generate removed Every in Optics plug-in --- .../src/main/kotlin/arrow/optics/plugin/internals/domain.kt | 1 - .../src/main/kotlin/arrow/optics/plugin/internals/dsl.kt | 6 ------ .../src/test/kotlin/arrow/optics/plugin/LensTests.kt | 1 - 3 files changed, 8 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt index e3bd7b7952d..6960a675805 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt @@ -120,7 +120,6 @@ const val Getter = "arrow.optics.Getter" const val Setter = "arrow.optics.Setter" const val Traversal = "arrow.optics.Traversal" const val Fold = "arrow.optics.Fold" -const val Every = "arrow.optics.Every" const val Tuple = "arrow.core.Tuple" const val Pair = "kotlin.Pair" const val Triple = "kotlin.Triple" diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt index a42decca9e3..6a1abfc40d6 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt @@ -33,7 +33,6 @@ private fun processLensSyntax(ele: ADT, foci: List): String = |${ele.visibilityModifierName} inline val $Setter.${focus.lensParamName()}: $Setter inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |${ele.visibilityModifierName} inline val $Traversal.${focus.lensParamName()}: $Traversal inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |${ele.visibilityModifierName} inline val $Fold.${focus.lensParamName()}: $Fold inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} - |${ele.visibilityModifierName} inline val $Every.${focus.lensParamName()}: $Every inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |""".trimMargin() } } else { @@ -49,7 +48,6 @@ private fun processLensSyntax(ele: ADT, foci: List): String = |${ele.visibilityModifierName} inline fun $Setter.${focus.lensParamName()}(): $Setter = this + ${ele.sourceClassName}.${focus.lensParamName()}() |${ele.visibilityModifierName} inline fun $Traversal.${focus.lensParamName()}(): $Traversal = this + ${ele.sourceClassName}.${focus.lensParamName()}() |${ele.visibilityModifierName} inline fun $Fold.${focus.lensParamName()}(): $Fold = this + ${ele.sourceClassName}.${focus.lensParamName()}() - |${ele.visibilityModifierName} inline fun $Every.${focus.lensParamName()}(): $Every = this + ${ele.sourceClassName}.${focus.lensParamName()}() |""".trimMargin() } } @@ -73,7 +71,6 @@ private fun processOptionalSyntax(ele: ADT, optic: DataClassDsl): String { |${ele.visibilityModifierName} inline val $Setter.${focus.paramName}: $Setter inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Traversal.${focus.paramName}: $Traversal inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Fold.${focus.paramName}: $Fold inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Every.${focus.paramName}: $Every inline get() = this + ${ele.sourceClassName}.${focus.paramName} |""".trimMargin() } else { """ @@ -84,7 +81,6 @@ private fun processOptionalSyntax(ele: ADT, optic: DataClassDsl): String { |${ele.visibilityModifierName} inline fun $Setter.${focus.paramName}(): $Setter = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Traversal.${focus.paramName}(): $Traversal = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Fold.${focus.paramName}(): $Fold = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Every.${focus.paramName}(): $Every = this + ${ele.sourceClassName}.${focus.paramName}() |""".trimMargin() } } @@ -101,7 +97,6 @@ private fun processPrismSyntax(ele: ADT, dsl: SealedClassDsl): String = |${ele.visibilityModifierName} inline val $Setter.${focus.paramName}: $Setter inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Traversal.${focus.paramName}: $Traversal inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Fold.${focus.paramName}: $Fold inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Every.${focus.paramName}: $Every inline get() = this + ${ele.sourceClassName}.${focus.paramName} |""".trimMargin() } } else { @@ -119,7 +114,6 @@ private fun processPrismSyntax(ele: ADT, dsl: SealedClassDsl): String = |${ele.visibilityModifierName} inline fun $Setter.${focus.paramName}(): $Setter = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Traversal.${focus.paramName}(): $Traversal = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Fold.${focus.paramName}(): $Fold = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Every.${focus.paramName}(): $Every = this + ${ele.sourceClassName}.${focus.paramName}() |""".trimMargin() } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt index 8afcae52b03..b66f4dac0dd 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/LensTests.kt @@ -1,6 +1,5 @@ package arrow.optics.plugin -import arrow.optics.plugin.internals.typeParametersErrorMessage import org.junit.jupiter.api.Test class LensTests { From 0246002a5c8ef5ea2c479cf38e5556619916a4b6 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Tue, 13 Dec 2022 21:32:53 +0100 Subject: [PATCH 06/11] Simplify optics to Traversal/Optional/Lens/Prism --- .../kotlin/arrow/optics/test/laws/IsoLaws.kt | 61 ---- .../arrow/optics/test/laws/SetterLaws.kt | 53 --- .../commonMain/kotlin/arrow/optics/Copy.kt | 10 +- .../commonMain/kotlin/arrow/optics/Every.kt | 2 +- .../commonMain/kotlin/arrow/optics/Fold.kt | 329 ------------------ .../commonMain/kotlin/arrow/optics/Getter.kt | 94 ----- .../src/commonMain/kotlin/arrow/optics/Iso.kt | 231 ------------ .../commonMain/kotlin/arrow/optics/Lens.kt | 18 +- .../kotlin/arrow/optics/Optional.kt | 17 +- .../kotlin/arrow/optics/OptionalGetter.kt | 124 ------- .../commonMain/kotlin/arrow/optics/Prism.kt | 11 +- .../commonMain/kotlin/arrow/optics/Setter.kt | 211 ----------- .../kotlin/arrow/optics/Traversal.kt | 153 ++++++-- .../commonMain/kotlin/arrow/optics/dsl/at.kt | 44 --- .../kotlin/arrow/optics/dsl/every.kt | 31 -- .../kotlin/arrow/optics/dsl/index.kt | 33 -- .../kotlin/arrow/optics/dsl/option.kt | 26 -- .../kotlin/arrow/optics/typeclasses/At.kt | 51 --- .../kotlin/arrow/optics/typeclasses/Cons.kt | 7 - .../arrow/optics/typeclasses/FilterIndex.kt | 10 +- .../kotlin/arrow/optics/typeclasses/Index.kt | 69 +--- .../kotlin/arrow/optics/typeclasses/Snoc.kt | 7 - .../kotlin/arrow/optics/FoldTest.kt | 89 ----- .../kotlin/arrow/optics/GetterTest.kt | 121 ------- .../commonTest/kotlin/arrow/optics/IsoTest.kt | 213 ------------ .../kotlin/arrow/optics/LensTest.kt | 26 -- .../kotlin/arrow/optics/OptionalGetterTest.kt | 24 -- .../kotlin/arrow/optics/PrismTest.kt | 8 - .../kotlin/arrow/optics/SetterTest.kt | 57 --- .../kotlin/arrow/optics/TestDomain.kt | 25 +- .../kotlin/arrow/optics/TraversalTest.kt | 8 - .../optics/instances/ConsInstanceTest.kt | 1 - .../kotlin/arrow/optics/std/ListTest.kt | 20 -- .../kotlin/arrow/optics/std/MapTest.kt | 24 -- .../kotlin/arrow/optics/std/OptionTest.kt | 22 -- .../kotlin/arrow/optics/std/StringTest.kt | 26 -- 36 files changed, 172 insertions(+), 2084 deletions(-) delete mode 100644 arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/IsoLaws.kt delete mode 100644 arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/SetterLaws.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/FoldTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/GetterTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalGetterTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/SetterTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt diff --git a/arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/IsoLaws.kt b/arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/IsoLaws.kt deleted file mode 100644 index 148ea91208a..00000000000 --- a/arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/IsoLaws.kt +++ /dev/null @@ -1,61 +0,0 @@ -package arrow.optics.test.laws - -import arrow.core.compose -import arrow.core.identity -import arrow.core.test.concurrency.deprecateArrowTestModules -import arrow.optics.Iso -import arrow.core.test.laws.Law -import arrow.core.test.laws.equalUnderTheLaw -import io.kotest.property.Arb -import io.kotest.property.PropertyContext -import io.kotest.property.checkAll - -@Deprecated(deprecateArrowTestModules)public object IsoLaws { - - @Deprecated(deprecateArrowTestModules) - public fun laws( - iso: Iso, - aGen: Arb, - bGen: Arb, - funcGen: Arb<(B) -> B>, - eqa: (A, A) -> Boolean = { a, b -> a == b }, - eqb: (B, B) -> Boolean = { a, b -> a == b } - ): List = - listOf( - Law("Iso Law: round trip one way") { iso.roundTripOneWay(aGen, eqa) }, - Law("Iso Law: round trip other way") { iso.roundTripOtherWay(bGen, eqb) }, - Law("Iso Law: modify identity is identity") { iso.modifyIdentity(aGen, eqa) }, - Law("Iso Law: compose modify") { iso.composeModify(aGen, funcGen, eqa) }, - Law("Iso Law: consitent set with modify") { iso.consistentSetModify(aGen, bGen, eqa) } - ) - - @Deprecated(deprecateArrowTestModules) - public suspend fun Iso.roundTripOneWay(aGen: Arb, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen) { a -> - reverseGet(get(a)).equalUnderTheLaw(a, eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Iso.roundTripOtherWay(bGen: Arb, eq: (B, B) -> Boolean): PropertyContext = - checkAll(100, bGen) { b -> - get(reverseGet(b)).equalUnderTheLaw(b, eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Iso.modifyIdentity(aGen: Arb, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen) { a -> - modify(a, ::identity).equalUnderTheLaw(a, eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Iso.composeModify(aGen: Arb, funcGen: Arb<(B) -> B>, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen, funcGen, funcGen) { a, f, g -> - modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Iso.consistentSetModify(aGen: Arb, bGen: Arb, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen, bGen) { a, b -> - set(b).equalUnderTheLaw(modify(a) { b }, eq) - } -} diff --git a/arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/SetterLaws.kt b/arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/SetterLaws.kt deleted file mode 100644 index 5cb7bb0edb4..00000000000 --- a/arrow-libs/optics/arrow-optics-test/src/commonMain/kotlin/arrow/optics/test/laws/SetterLaws.kt +++ /dev/null @@ -1,53 +0,0 @@ -package arrow.optics.test.laws - -import arrow.core.compose -import arrow.core.identity -import arrow.core.test.concurrency.deprecateArrowTestModules -import arrow.optics.Setter -import arrow.core.test.laws.Law -import arrow.core.test.laws.equalUnderTheLaw -import io.kotest.property.Arb -import io.kotest.property.PropertyContext -import io.kotest.property.checkAll - -@Deprecated(deprecateArrowTestModules) -public object SetterLaws { - - @Deprecated(deprecateArrowTestModules) - public fun laws( - setter: Setter, - aGen: Arb, - bGen: Arb, - funcGen: Arb<(B) -> B>, - eq: (A, A) -> Boolean = { a, b -> a == b } - ): List = listOf( - Law("Setter law: set is idempotent") { setter.setIdempotent(aGen, bGen, eq) }, - Law("Setter law: modify identity") { setter.modifyIdentity(aGen, eq) }, - Law("Setter law: compose modify") { setter.composeModify(aGen, eq, funcGen) }, - Law("Setter law: consistent set modify") { setter.consistentSetModify(aGen, bGen, eq) } - ) - - @Deprecated(deprecateArrowTestModules) - public suspend fun Setter.setIdempotent(aGen: Arb, bGen: Arb, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen, bGen) { a, b -> - set(set(a, b), b).equalUnderTheLaw(set(a, b), eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Setter.modifyIdentity(aGen: Arb, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen) { a -> - modify(a, ::identity).equalUnderTheLaw(a, eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Setter.composeModify(aGen: Arb, eq: (A, A) -> Boolean, funcGen: Arb<(B) -> B>): PropertyContext = - checkAll(100, aGen, funcGen, funcGen) { a, f, g -> - modify(modify(a, f), g).equalUnderTheLaw(modify(a, g compose f), eq) - } - - @Deprecated(deprecateArrowTestModules) - public suspend fun Setter.consistentSetModify(aGen: Arb, bGen: Arb, eq: (A, A) -> Boolean): PropertyContext = - checkAll(100, aGen, bGen) { a, b -> - modify(a) { b }.equalUnderTheLaw(set(a, b), eq) - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt index 3bdaae46d9b..3bfa3fd8e6a 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Copy.kt @@ -8,14 +8,14 @@ public annotation class OpticsCopyMarker @OpticsCopyMarker public interface Copy { /** - * Changes the value of the element(s) pointed by the [Setter]. + * Changes the value of the element(s) pointed by the [Traversal]. */ - public infix fun Setter.set(b: B) + public infix fun Traversal.set(b: B) /** * Transforms the value of the element(s) pointed by the [Traversal]. */ - public infix fun Setter.transform(f: (B) -> B) + public infix fun Traversal.transform(f: (B) -> B) /** * Declares a block in which all optics are nested within @@ -46,10 +46,10 @@ public interface Copy { // mutable builder of copies private class CopyImpl(var current: A): Copy { - override fun Setter.set(b: B) { + override fun Traversal.set(b: B) { current = this.set(current, b) } - override fun Setter.transform(f: (B) -> B) { + override fun Traversal.transform(f: (B) -> B) { current = this.modify(current, f) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt index 4cfd8df8ed7..d8d368a6e36 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Every.kt @@ -32,7 +32,7 @@ public object Every { /** * [Traversal] for [Either] that has focus in each [Either.Right]. * - * @receiver [Traversal.Companion] to make it statically available. + * @receiver [PTraversal.Companion] to make it statically available. * @return [Traversal] with source [Either] and focus every [Either.Right] of the source. */ @JvmStatic diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt deleted file mode 100644 index 2bc4e0cfbf9..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Fold.kt +++ /dev/null @@ -1,329 +0,0 @@ -package arrow.optics - -import arrow.core.Either -import arrow.core.NonEmptyList -import arrow.core.Option -import arrow.core.Tuple10 -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.foldMap -import arrow.core.identity -import arrow.typeclasses.Monoid -import kotlin.jvm.JvmStatic - -/** - * A [Fold] is an optic that allows to focus into structure and get multiple results. - * - * [Fold] is a generalisation of an instance of [Foldable] and is implemented in terms of foldMap. - * - * @param S the source of a [Fold] - * @param A the target of a [Fold] - */ -public interface Fold { - - /** - * Map each target to a type R and use a Monoid to fold the results - */ - public fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R - - /** - * Calculate the number of targets - */ - public fun size(source: S): Int = - foldMap(Monoid.int(), source) { 1 } - - /** - * Check if all targets satisfy the predicate - */ - public fun all(source: S, predicate: (focus: A) -> Boolean): Boolean = - foldMap(Monoid.boolean(), source, predicate) - - /** - * Returns `true` if at least one focus matches the given [predicate]. - */ - public fun any(source: S, predicate: (focus: A) -> Boolean): Boolean = - foldMap(Monoid.booleanOr(), source, predicate) - - /** - * Check if there is no target - */ - public fun isEmpty(source: S): Boolean = - foldMap(Monoid.boolean(), source) { false } - - /** - * Check if there is at least one target - */ - public fun isNotEmpty(source: S): Boolean = - !isEmpty(source) - - /** - * Get the first target or null - */ - @Suppress("UNCHECKED_CAST") - public fun firstOrNull(source: S): A? { - val fold = ::fold as (Monoid, S) -> Any? - val res = fold(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (a === EMPTY_VALUE) b else a - }, source) - return EMPTY_VALUE.unbox(res) - } - - /** - * Get the last target or null - */ - @Suppress("UNCHECKED_CAST") - public fun lastOrNull(source: S): A? { - val fold = ::fold as (Monoid, S) -> Any? - val res = fold(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (b !== EMPTY_VALUE) b else a - }, source) - return EMPTY_VALUE.unbox(res) - } - - /** - * Fold using the given [Monoid] instance. - */ - public fun fold(M: Monoid<@UnsafeVariance A>, source: S): A = - foldMap(M, source, ::identity) - - /** - * Alias for fold. - */ - @Deprecated("use fold instead", ReplaceWith("fold(M, source)")) - public fun combineAll(M: Monoid<@UnsafeVariance A>, source: S): A = - fold(M, source) - - /** - * Get all targets of the [Fold] - */ - public fun getAll(source: S): List = - foldMap(Monoid.list(), source, ::listOf) - - /** - * Find the first element matching the predicate, if one exists. - */ - public fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A? { - val res = foldMap(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (a === EMPTY_VALUE) b else a - }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } - return EMPTY_VALUE.unbox(res) - } - - /** - * Check whether at least one element satisfies the predicate. - * - * If there are no elements, the result is false. - */ - public fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean { - val res = foldMap(object : Monoid { - override fun empty(): Any = EMPTY_VALUE - override fun append(a: Any?, b: Any?): Any? = - if (a === EMPTY_VALUE) b else a - }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } - return res !== EMPTY_VALUE - } - - /** - * Join two [Fold] with the same target - */ - public infix fun choice(other: Fold): Fold, A> = - object : Fold, A> { - override fun foldMap(M: Monoid, source: Either, map: (focus: A) -> R): R = - source.fold({ ac -> this@Fold.foldMap(M, ac, map) }, { c -> other.foldMap(M, c, map) }) - } - - /** - * Create a sum of the [Fold] and a type [C] - */ - public fun left(): Fold, Either> = - object : Fold, Either> { - override fun foldMap(M: Monoid, source: Either, map: (Either) -> R): R = - source.fold( - { a1: S -> this@Fold.foldMap(M, a1) { b -> map(Either.Left(b)) } }, - { c -> map(Either.Right(c)) }) - } - - /** - * Create a sum of a type [C] and the [Fold] - */ - public fun right(): Fold, Either> = - object : Fold, Either> { - override fun foldMap(M: Monoid, source: Either, map: (Either) -> R): R = - source.fold({ c -> map(Either.Left(c)) }, { a1 -> this@Fold.foldMap(M, a1) { b -> map(Either.Right(b)) } }) - } - - /** - * Compose a [Fold] with a [Fold] - */ - public infix fun compose(other: Fold): Fold = - object : Fold { - override fun foldMap(M: Monoid, source: S, map: (focus: C) -> R): R = - this@Fold.foldMap(M, source) { c -> other.foldMap(M, c, map) } - } - - public operator fun plus(other: Fold): Fold = - this compose other - - public companion object { - - public fun id(): Fold = - PIso.id() - - /** - * [Fold] that takes either [S] or [S] and strips the choice of [S]. - */ - public fun codiagonal(): Fold, S> = object : Fold, S> { - override fun foldMap(M: Monoid, source: Either, map: (S) -> R): R = - source.fold(map, map) - } - - /** - * Creates a [Fold] based on a predicate of the source [S] - */ - public fun select(p: (S) -> Boolean): Fold = object : Fold { - override fun foldMap(M: Monoid, source: S, map: (S) -> R): R = - if (p(source)) map(source) else M.empty() - } - - /** - * [Fold] that points to nothing - */ - public fun void(): Fold = - POptional.void() - - @JvmStatic - public fun iterable(): Fold, A> = - object : Fold, A> { - override fun foldMap(M: Monoid, source: Iterable, map: (focus: A) -> R): R = - source.foldMap(M, map) - } - - /** - * [Traversal] for [List] that focuses in each [A] of the source [List]. - */ - @JvmStatic - public fun list(): Fold, A> = - Every.list() - - /** - * [Traversal] for [Either] that has focus in each [Either.Right]. - * - * @receiver [Traversal.Companion] to make it statically available. - * @return [Traversal] with source [Either] and focus every [Either.Right] of the source. - */ - @JvmStatic - public fun either(): Fold, R> = - Every.either() - - @JvmStatic - public fun map(): Fold, V> = - Every.map() - - /** - * [Traversal] for [NonEmptyList] that has focus in each [A]. - * - * @receiver [PTraversal.Companion] to make it statically available. - * @return [Traversal] with source [NonEmptyList] and focus every [A] of the source. - */ - @JvmStatic - public fun nonEmptyList(): Fold, A> = - Every.nonEmptyList() - - /** - * [Traversal] for [Option] that has focus in each [arrow.core.Some]. - * - * @receiver [PTraversal.Companion] to make it statically available. - * @return [Traversal] with source [Option] and focus in every [arrow.core.Some] of the source. - */ - @JvmStatic - public fun option(): Fold, A> = - Every.option() - - @JvmStatic - public fun sequence(): Fold, A> = - Every.sequence() - - /** - * [Traversal] for [String] that focuses in each [Char] of the source [String]. - * - * @receiver [PTraversal.Companion] to make it statically available. - * @return [Traversal] with source [String] and foci every [Char] in the source. - */ - @JvmStatic - public fun string(): Fold = - Every.string() - - /** - * [Traversal] to focus into the first and second value of a [Pair] - */ - @JvmStatic - public fun pair(): Fold, A> = - Every.pair() - - /** - * [Traversal] to focus into the first, second and third value of a [Triple] - */ - @JvmStatic - public fun triple(): Fold, A> = - Every.triple() - - /** - * [Traversal] to focus into the first, second, third and fourth value of a [arrow.core.Tuple4] - */ - @JvmStatic - public fun tuple4(): Fold, A> = - Every.tuple4() - - /** - * [PTraversal] to focus into the first, second, third, fourth and fifth value of a [arrow.core.Tuple5] - */ - @JvmStatic - public fun tuple5(): Fold, A> = - Every.tuple5() - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth and sixth value of a [arrow.core.Tuple6] - */ - @JvmStatic - public fun tuple6(): Fold, A> = - Every.tuple6() - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth and seventh value of a [arrow.core.Tuple7] - */ - @JvmStatic - public fun tuple7(): Fold, A> = - Every.tuple7() - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh and eight value of a [arrow.core.Tuple8] - */ - @JvmStatic - public fun tuple8(): Fold, A> = - Every.tuple8() - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight and ninth value of a [arrow.core.Tuple9] - */ - @JvmStatic - public fun tuple9(): Fold, A> = - Every.tuple9() - - /** - * [Traversal] to focus into the first, second, third, fourth, fifth, sixth, seventh, eight, ninth and tenth value of a [arrow.core.Tuple10] - */ - @JvmStatic - public fun tuple10(): Fold, A> = - Every.tuple10() - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt deleted file mode 100644 index b178100e881..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Getter.kt +++ /dev/null @@ -1,94 +0,0 @@ -package arrow.optics - -import arrow.core.Either -import arrow.core.compose -import arrow.core.identity -import arrow.typeclasses.Monoid - -public typealias Getter = PGetter - -/** - * A [Getter] is an optic that allows to see into a structure and getting a focus. - * - * A [Getter] can be seen as a get function: - * - `get: (S) -> A` meaning we can look into an `S` and get an `A` - * - * @param S the source of a [Getter] - * @param A the focus of a [Getter] - */ -public fun interface PGetter : POptionalGetter { - - /** - * Get the focus of a [Getter] - */ - public fun get(source: S): A - - override fun getOrModify(source: S): Either = - Either.Right(get(source)) - - override fun foldMap(M: Monoid, source: S, map: (A) -> R): R = - map(get(source)) - - /** - * Create a product of the [Getter] and a type [C] - */ - public override fun first(): PGetter, Pair, Pair> = - PGetter { (s, c) -> get(s) to c } - - /** - * Create a product of type [C] and the [Getter] - */ - public override fun second(): PGetter, Pair, Pair> = - PGetter { (c, s) -> c to get(s) } - - /** - * Create a sum of the [Getter] and type [C] - */ - override fun left(): PGetter, Either, Either> = - PGetter { sc -> sc.bimap(this::get, ::identity) } - - /** - * Create a sum of type [C] and the [Getter] - */ - override fun right(): PGetter, Either, Either> = - PGetter { cs -> cs.map(this::get) } - - /** - * Join two [Getter] with the same focus - */ - public infix fun choice(other: PGetter): PGetter, Either, A> = - PGetter { s -> s.fold(this::get, other::get) } - - /** - * Pair two disjoint [Getter] - */ - public infix fun split(other: PGetter): PGetter, Pair, Pair> = - PGetter { (s, c) -> get(s) to other.get(c) } - - /** - * Zip two [Getter] optics with the same source [S] - */ - public infix fun zip(other: PGetter<@UnsafeVariance S, @UnsafeVariance T, C>): PGetter> = - PGetter { s -> get(s) to other.get(s) } - - /** - * Compose a [Getter] with a [Getter] - */ - public infix fun compose(other: PGetter): PGetter = - PGetter(other::get compose this::get) - - public operator fun plus(other: PGetter): PGetter = - this compose other - - public companion object { - - public fun id(): Getter = - PIso.id() - - /** - * [Getter] that takes either [S] or [S] and strips the choice of [S]. - */ - public fun codiagonal(): Getter, S> = - Getter { aa -> aa.fold(::identity, ::identity) } - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt deleted file mode 100644 index 918ab44d37e..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Iso.kt +++ /dev/null @@ -1,231 +0,0 @@ -package arrow.optics - -import arrow.core.Either -import arrow.core.NonEmptyList -import arrow.core.None -import arrow.core.Option -import arrow.core.Either.Right -import arrow.core.Some -import arrow.core.compose -import arrow.core.identity -import arrow.typeclasses.Monoid -import kotlin.jvm.JvmStatic - -/** - * [Iso] is a type alias for [PIso] which fixes the type arguments - * and restricts the [PIso] to monomorphic updates. - */ -public typealias Iso = PIso - -private val stringToList: Iso> = - Iso( - get = CharSequence::toList, - reverseGet = { it.joinToString(separator = "") } - ) - -/** - * An [Iso] is a loss less invertible optic that defines an isomorphism between a type [S] and [A] - * i.e. a data class and its properties represented by TupleN - * - * A (polymorphic) [PIso] is useful when setting or modifying a value for a constructed type - * i.e. PIso, Option, Int?, String?> - * - * An [PIso] is also a valid [PLens], [PPrism] - * - * @param S the source of a [PIso] - * @param T the modified source of a [PIso] - * @param A the focus of a [PIso] - * @param B the modified target of a [PIso] - */ -public interface PIso : PPrism, PLens { - - /** - * Get the focus of a [PIso] - */ - override fun get(source: S): A - - /** - * Get the modified focus of a [PIso] - */ - override fun reverseGet(focus: B): T - - override fun getOrModify(source: S): Either = - Either.Right(get(source)) - - override fun set(source: S, focus: B): T = - set(focus) - - /** - * Modify polymorphically the focus of a [PIso] with a function - */ - override fun modify(source: S, map: (focus: A) -> B): T = - reverseGet(map(get(source))) - - override fun foldMap(M: Monoid, source: S, map: (A) -> R): R = - map(get(source)) - - /** - * Reverse a [PIso]: the source becomes the target and the target becomes the source - */ - public fun reverse(): PIso = - PIso(this::reverseGet, this::get) - - /** - * Set polymorphically the focus of a [PIso] with a value - */ - public fun set(b: B): T = - reverseGet(b) - - /** - * Pair two disjoint [PIso] - */ - public infix fun split(other: PIso): PIso, Pair, Pair, Pair> = - PIso( - { (a, c) -> get(a) to other.get(c) }, - { (b, d) -> reverseGet(b) to other.reverseGet(d) } - ) - - /** - * Create a pair of the [PIso] and a type [C] - */ - override fun first(): PIso, Pair, Pair, Pair> = Iso( - { (a, c) -> get(a) to c }, - { (b, c) -> reverseGet(b) to c } - ) - - /** - * Create a pair of a type [C] and the [PIso] - */ - override fun second(): PIso, Pair, Pair, Pair> = PIso( - { (c, a) -> c to get(a) }, - { (c, b) -> c to reverseGet(b) } - ) - - /** - * Create a sum of the [PIso] and a type [C] - */ - override fun left(): PIso, Either, Either, Either> = PIso( - { it.bimap(this::get, ::identity) }, - { it.bimap(this::reverseGet, ::identity) } - ) - - /** - * Create a sum of a type [C] and the [PIso] - */ - override fun right(): PIso, Either, Either, Either> = PIso( - { it.bimap(::identity, this::get) }, - { it.bimap(::identity, this::reverseGet) } - ) - - /** - * Compose a [PIso] with a [PIso] - */ - public infix fun compose(other: PIso): PIso = PIso( - other::get compose this::get, - this::reverseGet compose other::reverseGet - ) - - public operator fun plus(other: PIso): PIso = - this compose other - - public companion object { - - /** - * create an [PIso] between any type and itself. - * Id is the zero element of optics composition, for any optic o of type O (e.g. PLens, Prism, POptional, ...): - * o compose Iso.id == o - */ - public fun id(): Iso = Iso(::identity, ::identity) - - /** - * Invoke operator overload to create a [PIso] of type `S` with target `A`. - * Can also be used to construct [Iso] - */ - public operator fun invoke(get: (S) -> (A), reverseGet: (B) -> T): PIso = - object : PIso { - override fun get(source: S): A = get(source) - override fun reverseGet(focus: B): T = reverseGet(focus) - } - - /** - * [PIso] that defines equality between a [List] and [Option] [NonEmptyList] - */ - @JvmStatic - public fun listToPOptionNel(): PIso, List, Option>, Option>> = - PIso( - get = { aas -> if (aas.isEmpty()) None else Some(NonEmptyList(aas.first(), aas.drop(1))) }, - reverseGet = { optNel -> optNel.fold({ emptyList() }, NonEmptyList::all) } - ) - - /** - * [Iso] that defines equality between a [List] and [Option] [NonEmptyList] - */ - @JvmStatic - public fun listToOptionNel(): Iso, Option>> = - listToPOptionNel() - - /** - * [Iso] that defines the equality between a Unit value [Map] and a [Set] with its keys - */ - @JvmStatic - public fun mapToSet(): Iso, Set> = - Iso( - get = { it.keys }, - reverseGet = { keys -> keys.map { it to Unit }.toMap() } - ) - - /** - * [PIso] that defines the equality between the nullable platform type and [Option]. - */ - @JvmStatic - public fun nullableToPOption(): PIso, Option> = - PIso( - get = Option.Companion::fromNullable, - reverseGet = { it.fold({ null }, ::identity) } - ) - - @JvmStatic - public fun nullableToOption(): PIso, Option> = - nullableToPOption() - - /** - * [PIso] that defines the equality between [Option] and the nullable platform type. - */ - @JvmStatic - public fun optionToPNullable(): PIso, Option, A?, B?> = - PIso( - get = { it.fold({ null }, ::identity) }, - reverseGet = Option.Companion::fromNullable - ) - - /** - * [PIso] that defines the isomorphic relationship between [Option] and the nullable platform type. - */ - @JvmStatic - public fun optionToNullable(): Iso, A?> = optionToPNullable() - - /** - * [Iso] that defines the equality between and [arrow.core.Option] and [arrow.core.Either] - */ - @JvmStatic - public fun optionToPEither(): PIso, Option, Either, Either> = - PIso( - get = { opt -> opt.fold({ Either.Left(Unit) }, ::Right) }, - reverseGet = { either -> either.fold({ None }, ::Some) } - ) - - /** - * [Iso] that defines the equality between and [arrow.core.Option] and [arrow.core.Either] - */ - @JvmStatic - public fun optionToEither(): Iso, Either> = - optionToPEither() - - /** - * [Iso] that defines equality between String and [List] of [Char] - */ - @JvmStatic - public fun stringToList(): Iso> = - stringToList - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt index b45855d4554..a5fb50de607 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Lens.kt @@ -28,9 +28,9 @@ public typealias Lens = PLens * @param A the focus of a [PLens] * @param B the modified focus of a [PLens] */ -public interface PLens : PGetter, POptional { +public interface PLens : POptional { - override fun get(source: S): A + public fun get(source: S): A override fun set(source: S, focus: B): T @@ -86,7 +86,10 @@ public interface PLens : PGetter, POptional { public companion object { - public fun id(): PIso = PIso.id() + public fun id(): Lens = Lens( + get = { it }, + set = { _, s -> s } + ) /** * [PLens] that takes either [S] or [S] and strips the choice of [S]. @@ -210,5 +213,14 @@ public interface PLens : PGetter, POptional { @JvmStatic public fun tripleThird(): Lens, C> = triplePThird() + + /** + * Defines equality between String and [List] of [Char] + */ + @JvmStatic + public fun stringToList(): Lens> = PLens( + get = CharSequence::toList, + set = { _, ss -> ss.joinToString(separator = "") } + ) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index 5d2f263742c..f8fd663cf69 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -17,7 +17,6 @@ import kotlin.jvm.JvmStatic */ public typealias Optional = POptional -@Suppress("FunctionName") public fun Optional(getOption: (source: S) -> Option, set: (source: S, focus: A) -> S): Optional = POptional({ s -> getOption(s).toEither { s } }, set) @@ -60,7 +59,7 @@ public fun Optional(getOption: (source: S) -> Option, set: (source: S, * @param A the focus of a [POptional] * @param B the modified focus of a [POptional] */ -public interface POptional : POptionalGetter, PTraversal { +public interface POptional : PTraversal { /** * Get the modified source of a [POptional] @@ -70,7 +69,13 @@ public interface POptional : POptionalGetter, PTraversal + public fun getOrModify(source: S): Either + + /** + * Get the focus of an [Optional] or `null` if the is not there + */ + public fun getOrNull(source: S): A? = + getOrModify(source).getOrNull() override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R = getOrModify(source).map(map).fold({ M.empty() }, ::identity) @@ -118,7 +123,7 @@ public interface POptional : POptionalGetter, PTraversal first(): POptional, Pair, Pair, Pair> = + public fun first(): POptional, Pair, Pair, Pair> = POptional( { (source, c) -> getOrModify(source).bimap({ Pair(it, c) }, { Pair(it, c) }) }, { (source, c2), (update, c) -> setNullable(source, update)?.let { Pair(it, c) } ?: Pair(set(source, update), c2) } @@ -127,7 +132,7 @@ public interface POptional : POptionalGetter, PTraversal second(): POptional, Pair, Pair, Pair> = + public fun second(): POptional, Pair, Pair, Pair> = POptional( { (c, s) -> getOrModify(s).bimap({ c to it }, { c to it }) }, { (c2, s), (c, b) -> setNullable(s, b)?.let { c to it } ?: (c2 to set(s, b)) } @@ -151,7 +156,7 @@ public interface POptional : POptionalGetter, PTraversal id(): PIso = PIso.id() + public fun id(): Optional = PLens.id() /** * [POptional] that takes either [S] or [S] and strips the choice of [S]. diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt deleted file mode 100644 index c43315e5460..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/OptionalGetter.kt +++ /dev/null @@ -1,124 +0,0 @@ -package arrow.optics - -import arrow.core.Either -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import arrow.core.flatMap -import arrow.core.identity -import arrow.typeclasses.Monoid -import kotlin.jvm.JvmStatic - -/** - * [OptionalGetter] is a type alias for [POptionalGetter] which fixes the type arguments - * and restricts the [POptionalGetter] to monomorphic updates. - */ -public typealias OptionalGetter = POptionalGetter - -public fun OptionalGetter(getOption: (source: S) -> Option): OptionalGetter = - POptionalGetter({ s -> getOption(s).toEither { s } }) - -/** - * An [OptionalGetter] is an optic that allows into a structure and querying an optional focus. - * - * @param S the source of a [POptional] - * @param T the modified source of a [POptional] - * @param A the focus of a [POptional] - */ -public interface POptionalGetter: Fold { - /** - * Get the focus of an [OptionalGetter] or return the original value while allowing the type to change if it does not match - */ - public fun getOrModify(source: S): Either - - /** - * Get the focus of an [OptionalGetter] or `null` if the is not there - */ - public fun getOrNull(source: S): A? = - getOrModify(source).orNull() - - override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R = - getOrModify(source).map(map).fold({ M.empty() }, ::identity) - - /** - * Join two [POptionalGetter] with the same focus - */ - public infix fun choice(other: POptionalGetter): POptionalGetter, Either, A> = - POptionalGetter( - { sources -> - sources.fold( - { leftSource -> - getOrModify(leftSource).bimap({ Either.Left(it) }, ::identity) - }, - { rightSource -> - other.getOrModify(rightSource).bimap({ Either.Right(it) }, ::identity) - } - ) - } - ) - - /** - * Create a product of the [POptionalGetter] and a type [C] - */ - public fun first(): POptionalGetter, Pair, Pair> = - POptionalGetter( - { (source, c) -> getOrModify(source).bimap({ Pair(it, c) }, { Pair(it, c) }) } - ) - - /** - * Create a product of a type [C] and the [POptionalGetter] - */ - public fun second(): POptionalGetter, Pair, Pair> = - POptionalGetter( - { (c, s) -> getOrModify(s).bimap({ c to it }, { c to it }) } - ) - - /** - * Compose a [POptionalGetter] with a [POptionalGetter] - */ - public infix fun compose(other: POptionalGetter): POptionalGetter = - POptionalGetter( - { source -> - getOrModify(source).flatMap { a -> - other.getOrModify(a) - } - } - ) - - public operator fun plus(other: POptionalGetter): POptionalGetter = - this compose other - - public companion object { - /** - * Invoke operator overload to create an [OptionalGetter] of type `S` with focus `A`. - */ - public operator fun invoke( - getOrModify: (source: S) -> Either - ): POptionalGetter = object : POptionalGetter { - override fun getOrModify(source: S): Either = getOrModify(source) - } - - public fun id(): PIso = PIso.id() - - /** - * [OptionalGetter] to itself if it satisfies the predicate. - * - * Select all the elements which satisfy the predicate. - * - * ```kotlin - * import arrow.optics.Traversal - * import arrow.optics.Optional - * - * val positiveNumbers = Traversal.list() compose OptionalGetter.filter { it >= 0 } - * - * positiveNumbers.getAll(listOf(1, 2, -3, 4, -5)) == listOf(1, 2, 4) - * ``` - */ - @JvmStatic - public fun filter(predicate: (A) -> Boolean): OptionalGetter = - OptionalGetter( - getOption = { if (predicate(it)) Some(it) else None } - ) - } -} - diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 990e462d4b0..5b6bbcdb7ed 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -7,6 +7,7 @@ import arrow.core.Some import arrow.core.compose import arrow.core.flatMap import arrow.core.identity +import arrow.core.right import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic @@ -80,7 +81,7 @@ public interface PPrism : POptional { /** * Create a sum of the [PPrism] and a type [C] */ - override fun left(): PPrism, Either, Either, Either> = + public fun left(): PPrism, Either, Either, Either> = PPrism( { it.fold( @@ -98,7 +99,7 @@ public interface PPrism : POptional { /** * Create a sum of a type [C] and the [PPrism] */ - override fun right(): PPrism, Either, Either, Either> = + public fun right(): PPrism, Either, Either, Either> = PPrism( { it.fold( @@ -122,7 +123,10 @@ public interface PPrism : POptional { public companion object { - public fun id(): PIso = PIso.id() + public fun id(): Prism = PPrism( + getOrModify = { it.right() }, + reverseGet = ::identity + ) /** * Invoke operator overload to create a [PPrism] of type `S` with focus `A`. @@ -179,7 +183,6 @@ public interface PPrism : POptional { * Invoke operator overload to create a [PPrism] of type `S` with a focus `A` where `A` is a subtype of `S` * Can also be used to construct [Prism] */ -@Suppress("FunctionName") public fun Prism(getOption: (source: S) -> Option, reverseGet: (focus: A) -> S): Prism = Prism( getOrModify = { getOption(it).toEither { it } }, reverseGet = { reverseGet(it) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt deleted file mode 100644 index d74b95d8819..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Setter.kt +++ /dev/null @@ -1,211 +0,0 @@ -package arrow.optics - -import arrow.core.Either - -/** - * [Setter] is a type alias for [PSetter] which fixes the type arguments - * and restricts the [PSetter] to monomorphic updates. - */ -public typealias Setter = PSetter - -/** - * A [Setter] is an optic that allows to see into a structure and set or modify its focus. - * - * A (polymorphic) [PSetter] is useful when setting or modifying a value for a constructed type - * i.e. PSetter, List, Int, String> - * - * A [PSetter] is a generalisation of a [arrow.Functor]. - * Functor::map (fa: Kind, f: (A) -> B): Kind - * PSetter::modify(s: S, f: (A) -> B): T - * - * @param S the source of a [PSetter] - * @param T the modified source of a [PSetter] - * @param A the focus of a [PSetter] - * @param B the modified focus of a [PSetter] - */ -public fun interface PSetter { - - /** - * Modify polymorphically the focus of a [PSetter] with a function [map]. - */ - public fun modify(source: S, map: (focus: A) -> B): T - - /** - * Set polymorphically the focus of a [PSetter] with a value [b]. - */ - public fun set(source: S, focus: B): T = - modify(source) { focus } - - /** - * Lift a function [map]: `(A) -> B to the context of `S`: `(S) -> T` - */ - public fun lift(map: (focus: A) -> B): (source: S) -> T = - { s -> modify(s) { map(it) } } - - /** - * Join two [PSetter] with the same target - */ - public infix fun choice(other: PSetter): PSetter, Either, A, B> = - PSetter { su, f -> - su.bimap({ s -> modify(s, f) }, { u -> other.modify(u, f) }) - } - - /** - * Compose a [PSetter] with a [PSetter] - */ - public infix fun compose(other: PSetter): PSetter = - PSetter { s, fb -> modify(s) { a -> other.modify(a, fb) } } - - public operator fun plus(other: PSetter): PSetter = - this compose other - - public companion object { - - public fun id(): PSetter = - PIso.id() - - /** - * [PSetter] that takes either S or S and strips the choice of S. - */ - public fun codiagonal(): Setter, S> = - Setter { aa, f -> aa.bimap(f, f) } - - /** - * [PTraversal] constructor from multiple getters of the same source. - */ - public operator fun invoke(get1: (S) -> A, get2: (S) -> A, set: (B, B, S) -> T): PSetter = - PSetter { s, f -> set(f(get1(s)), f(get2(s)), s) } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - set: (B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), s) } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - set: (B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), s) } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - get5: (S) -> A, - set: (B, B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), s) } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - get5: (S) -> A, - get6: (S) -> A, - set: (B, B, B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), s) } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - get5: (S) -> A, - get6: (S) -> A, - get7: (S) -> A, - set: (B, B, B, B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> set(f(get1(s)), f(get2(s)), f(get3(s)), f(get4(s)), f(get5(s)), f(get6(s)), f(get7(s)), s) } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - get5: (S) -> A, - get6: (S) -> A, - get7: (S) -> A, - get8: (S) -> A, - set: (B, B, B, B, B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> - set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - s - ) - } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - get5: (S) -> A, - get6: (S) -> A, - get7: (S) -> A, - get8: (S) -> A, - get9: (S) -> A, - set: (B, B, B, B, B, B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> - set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - f(get9(s)), - s - ) - } - - public operator fun invoke( - get1: (S) -> A, - get2: (S) -> A, - get3: (S) -> A, - get4: (S) -> A, - get5: (S) -> A, - get6: (S) -> A, - get7: (S) -> A, - get8: (S) -> A, - get9: (S) -> A, - get10: (S) -> A, - set: (B, B, B, B, B, B, B, B, B, B, S) -> T - ): PSetter = - PSetter { s, f -> - set( - f(get1(s)), - f(get2(s)), - f(get3(s)), - f(get4(s)), - f(get5(s)), - f(get6(s)), - f(get7(s)), - f(get8(s)), - f(get9(s)), - f(get10(s)), - s - ) - } - - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt index 10961e9f538..5060254b364 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Traversal.kt @@ -10,6 +10,7 @@ import arrow.core.Tuple6 import arrow.core.Tuple7 import arrow.core.Tuple8 import arrow.core.Tuple9 +import arrow.core.identity import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic @@ -30,15 +31,33 @@ public typealias Traversal = PTraversal * @param A the target of a [PTraversal] * @param B the modified target of a [PTraversal] */ -public interface PTraversal : PSetter, Fold { +public interface PTraversal { /** * Map each target to a type R and use a Monoid to fold the results */ - override fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R + public fun foldMap(M: Monoid, source: S, map: (focus: A) -> R): R - override fun modify(source: S, map: (focus: A) -> B): T + /** + * Modify polymorphically the focus of a [PTraversal] with a function [map]. + */ + public fun modify(source: S, map: (focus: A) -> B): T + + /** + * Set polymorphically the focus of a [PTraversal] with a value [focus]. + */ + public fun set(source: S, focus: B): T = + modify(source) { focus } + /** + * Lift a function [map]: `(A) -> B to the context of `S`: `(S) -> T` + */ + public fun lift(map: (focus: A) -> B): (source: S) -> T = + { s -> modify(s) { map(it) } } + + /** + * Join two [PTraversal] with the same target + */ public fun choice(other: PTraversal): PTraversal, Either, A, B> = object : PTraversal, Either, A, B> { override fun foldMap(M: Monoid, source: Either, map: (A) -> R): R = @@ -69,10 +88,112 @@ public interface PTraversal : PSetter, Fold { public operator fun plus(other: PTraversal): PTraversal = this compose other + /** + * Calculate the number of targets + */ + public fun size(source: S): Int = + foldMap(Monoid.int(), source) { 1 } + + /** + * Check if all targets satisfy the predicate + */ + public fun all(source: S, predicate: (focus: A) -> Boolean): Boolean = + foldMap(Monoid.boolean(), source, predicate) + + /** + * Returns `true` if at least one focus matches the given [predicate]. + */ + public fun any(source: S, predicate: (focus: A) -> Boolean): Boolean = + foldMap(Monoid.booleanOr(), source, predicate) + + /** + * Check if there is no target + */ + public fun isEmpty(source: S): Boolean = + foldMap(Monoid.boolean(), source) { false } + + /** + * Check if there is at least one target + */ + public fun isNotEmpty(source: S): Boolean = + !isEmpty(source) + + /** + * Get the first target or null + */ + @Suppress("UNCHECKED_CAST") + public fun firstOrNull(source: S): A? { + val fold = ::fold as (Monoid, S) -> Any? + val res = fold(object : Monoid { + override fun empty(): Any = EMPTY_VALUE + override fun append(a: Any?, b: Any?): Any? = + if (a === EMPTY_VALUE) b else a + }, source) + return EMPTY_VALUE.unbox(res) + } + + /** + * Get the last target or null + */ + @Suppress("UNCHECKED_CAST") + public fun lastOrNull(source: S): A? { + val fold = ::fold as (Monoid, S) -> Any? + val res = fold(object : Monoid { + override fun empty(): Any = EMPTY_VALUE + override fun append(a: Any?, b: Any?): Any? = + if (b !== EMPTY_VALUE) b else a + }, source) + return EMPTY_VALUE.unbox(res) + } + + /** + * Fold using the given [Monoid] instance. + */ + public fun fold(M: Monoid<@UnsafeVariance A>, source: S): A = + foldMap(M, source, ::identity) + + /** + * Alias for fold. + */ + @Deprecated("use fold instead", ReplaceWith("fold(M, source)")) + public fun combineAll(M: Monoid<@UnsafeVariance A>, source: S): A = + fold(M, source) + + /** + * Get all targets of the [Traversal] + */ + public fun getAll(source: S): List = + foldMap(Monoid.list(), source, ::listOf) + + /** + * Find the first element matching the predicate, if one exists. + */ + public fun findOrNull(source: S, predicate: (focus: A) -> Boolean): A? { + val res = foldMap(object : Monoid { + override fun empty(): Any = EMPTY_VALUE + override fun append(a: Any?, b: Any?): Any? = + if (a === EMPTY_VALUE) b else a + }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } + return EMPTY_VALUE.unbox(res) + } + + /** + * Check whether at least one element satisfies the predicate. + * + * If there are no elements, the result is false. + */ + public fun exists(source: S, predicate: (focus: A) -> Boolean): Boolean { + val res = foldMap(object : Monoid { + override fun empty(): Any = EMPTY_VALUE + override fun append(a: Any?, b: Any?): Any? = + if (a === EMPTY_VALUE) b else a + }, source) { focus -> if (predicate(focus)) focus else EMPTY_VALUE } + return res !== EMPTY_VALUE + } + public companion object { - public fun id(): PTraversal = - PIso.id() + public fun id(): Traversal = PLens.id() public fun codiagonal(): Traversal, S> = object : Traversal, S> { @@ -250,7 +371,7 @@ public interface PTraversal : PSetter, Fold { /** * [Traversal] for [Either] that has focus in each [Either.Right]. * - * @receiver [Traversal.Companion] to make it statically available. + * @receiver [PTraversal.Companion] to make it statically available. * @return [Traversal] with source [Either] and focus every [Either.Right] of the source. */ @JvmStatic @@ -504,16 +625,6 @@ public interface PTraversal : PSetter, Fold { get() = this@every.compose(this@PTraversal) - /** - * DSL to compose [Traversal] with a [Iso] for a structure [S] to see all its foci [A] - * - * @receiver [Iso] with a focus in [S] - * @return [Traversal] with a focus in [A] - */ - public val PIso.every: PTraversal - get() = - this@every.compose(this@PTraversal) - /** * DSL to compose [Traversal] with a [Prism] for a structure [S] to see all its foci [A] * @@ -534,16 +645,6 @@ public interface PTraversal : PSetter, Fold { get() = this.compose(this@PTraversal) - /** - * DSL to compose [Traversal] with a [Setter] for a structure [S] to see all its foci [A] - * - * @receiver [Setter] with a focus in [S] - * @return [Setter] with a focus in [A] - */ - public val PSetter.every: PSetter - get() = - this.compose(this@PTraversal) - /** * DSL to compose [Traversal] with a [Traversal] for a structure [S] to see all its foci [A] * diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt index 5b8f6e8f7a3..55b42bd4257 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt @@ -1,12 +1,8 @@ package arrow.optics.dsl -import arrow.optics.Fold -import arrow.optics.Getter -import arrow.optics.Iso import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.Prism -import arrow.optics.Setter import arrow.optics.Traversal import arrow.optics.typeclasses.At @@ -20,16 +16,6 @@ import arrow.optics.typeclasses.At */ public fun Lens.at(AT: At, i: I): Lens = this.compose(AT.at(i)) -/** - * DSL to compose [At] with an [Iso] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Iso] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Lens] with a focus in [A] at given index [I]. - */ -public fun Iso.at(AT: At, i: I): Lens = this.compose(AT.at(i)) - /** * DSL to compose [At] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. * @@ -50,26 +36,6 @@ public fun Prism.at(AT: At, i: I): Optional = */ public fun Optional.at(AT: At, i: I): Optional = this.compose(AT.at(i)) -/** - * DSL to compose [At] with a [Getter] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Getter] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Getter] with a focus in [A] at given index [I]. - */ -public fun Getter.at(AT: At, i: I): Getter = this.compose(AT.at(i)) - -/** - * DSL to compose [At] with a [Setter] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Setter] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Setter] with a focus in [A] at given index [I]. - */ -public fun Setter.at(AT: At, i: I): Setter = this.compose(AT.at(i)) - /** * DSL to compose [At] with a [Traversal] for a structure [S] to focus in on [A] at given index [I]. * @@ -79,13 +45,3 @@ public fun Setter.at(AT: At, i: I): Setter = t * @return [Traversal] with a focus in [A] at given index [I]. */ public fun Traversal.at(AT: At, i: I): Traversal = this.compose(AT.at(i)) - -/** - * DSL to compose [At] with a [Fold] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Fold] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Fold] with a focus in [A] at given index [I]. - */ -public fun Fold.at(AT: At, i: I): Fold = this.compose(AT.at(i)) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt index eeda5c26ffe..ce4f13f70cb 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt @@ -1,12 +1,8 @@ package arrow.optics.dsl -import arrow.optics.Every -import arrow.optics.Fold -import arrow.optics.Iso import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.Prism -import arrow.optics.Setter import arrow.optics.Traversal /** @@ -18,15 +14,6 @@ import arrow.optics.Traversal */ public fun Lens.every(TR: Traversal): Traversal = this.compose(TR) -/** - * DSL to compose [Traversal] with an [Iso] for a structure [S] to see all its foci [A] - * - * @receiver [Iso] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] - * @return [Traversal] with a focus in [A] - */ -public fun Iso.every(TR: Traversal): Traversal = this.compose(TR) - /** * DSL to compose [Traversal] with a [Prism] for a structure [S] to see all its foci [A] * @@ -45,15 +32,6 @@ public fun Prism.every(TR: Traversal): Traversal = t */ public fun Optional.every(TR: Traversal): Traversal = this.compose(TR) -/** - * DSL to compose [Traversal] with a [Setter] for a structure [S] to see all its foci [A] - * - * @receiver [Setter] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] - * @return [Setter] with a focus in [A] - */ -public fun Setter.every(TR: Traversal): Setter = this.compose(TR) - /** * DSL to compose [Traversal] with a [Traversal] for a structure [S] to see all its foci [A] * @@ -62,12 +40,3 @@ public fun Setter.every(TR: Traversal): Setter = thi * @return [Traversal] with a focus in [A] */ public fun Traversal.every(TR: Traversal): Traversal = this.compose(TR) - -/** - * DSL to compose [Traversal] with a [Fold] for a structure [S] to see all its foci [A] - * - * @receiver [Fold] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] - * @return [Fold] with a focus in [A] - */ -public fun Fold.every(TR: Traversal): Fold = this.compose(TR) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt index c9682f8066c..241c9f34790 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt @@ -1,11 +1,8 @@ package arrow.optics.dsl -import arrow.optics.Fold -import arrow.optics.Iso import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.Prism -import arrow.optics.Setter import arrow.optics.Traversal import arrow.optics.typeclasses.Index @@ -19,16 +16,6 @@ import arrow.optics.typeclasses.Index */ public fun Lens.index(ID: Index, i: I): Optional = this.compose(ID.index(i)) -/** - * DSL to compose [Index] with an [Iso] for a structure [S] to focus in on [A] at given index [I] - * - * @receiver [Iso] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I] - */ -public fun Iso.index(ID: Index, i: I): Optional = this.compose(ID.index(i)) - /** * DSL to compose [Index] with a [Prism] for a structure [S] to focus in on [A] at given index [I] * @@ -49,16 +36,6 @@ public fun Prism.index(ID: Index, i: I): Optional Optional.index(ID: Index, i: I): Optional = this.compose(ID.index(i)) -/** - * DSL to compose [Index] with a [Setter] for a structure [S] to focus in on [A] at given index [I] - * - * @receiver [Setter] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Setter] with a focus in [A] at given index [I]. - */ -public fun Setter.index(ID: Index, i: I): Setter = this.compose(ID.index(i)) - /** * DSL to compose [Index] with a [Traversal] for a structure [S] to focus in on [A] at given index [I] * @@ -68,13 +45,3 @@ public fun Setter.index(ID: Index, i: I): Setter Traversal.index(ID: Index, i: I): Traversal = this.compose(ID.index(i)) - -/** - * DSL to compose [Index] with a [Fold] for a structure [S] to focus in on [A] at given index [I] - * - * @receiver [Fold] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Fold] with a focus in [A] at given index [I]. - */ -public fun Fold.index(ID: Index, i: I): Fold = this.compose(ID.index(i)) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt index 64a45d2e3be..a6ec24ab31b 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt @@ -1,12 +1,9 @@ package arrow.optics.dsl import arrow.core.Option -import arrow.optics.Fold -import arrow.optics.Iso import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.Prism -import arrow.optics.Setter import arrow.optics.Traversal /** @@ -17,13 +14,6 @@ import arrow.optics.Traversal */ public inline val Lens>.some: Optional inline get() = this.compose(Prism.some()) -/** - * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Iso] with a focus of [Option]<[S]> - * - * @receiver [Iso] with a focus in [Option]<[S]> - * @return [Prism] with a focus in [S] - */ -public inline val Iso>.some: Prism inline get() = this.compose(Prism.some()) /** * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Prism] with a focus of [Option]<[S]> @@ -41,14 +31,6 @@ public inline val Prism>.some: Prism inline get() = th */ public inline val Optional>.some: Optional inline get() = this.compose(Prism.some()) -/** - * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Setter] with a focus of [Option]<[S]> - * - * @receiver [Setter] with a focus in [Option]<[S]> - * @return [Setter] with a focus in [S] - */ -public inline val Setter>.some: Setter inline get() = this.compose(Prism.some()) - /** * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Traversal] with a focus of [Option]<[S]> * @@ -56,11 +38,3 @@ public inline val Setter>.some: Setter inline get() = * @return [Traversal] with a focus in [S] */ public inline val Traversal>.some: Traversal inline get() = this.compose(Prism.some()) - -/** - * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Fold] with a focus of [Option]<[S]> - * - * @receiver [Fold] with a focus in [Option]<[S]> - * @return [Fold] with a focus in [S] - */ -public inline val Fold>.some: Fold inline get() = this.compose(Prism.some()) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt index 4f3dee12bd5..41fd39e9139 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt @@ -2,14 +2,10 @@ package arrow.optics.typeclasses import arrow.core.None import arrow.core.Option -import arrow.optics.Fold -import arrow.optics.Getter -import arrow.optics.Iso import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.PLens import arrow.optics.Prism -import arrow.optics.Setter import arrow.optics.Traversal import kotlin.jvm.JvmStatic @@ -40,16 +36,6 @@ public fun interface At { public fun Lens.at(i: I): Lens = this@at.compose(this@At.at(i)) - /** - * DSL to compose [At] with an [Iso] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Iso] with a focus in [S] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Lens] with a focus in [A] at given index [I]. - */ - public fun Iso.at(i: I): Lens = - this.compose(this@At.at(i)) - /** * DSL to compose [At] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. * @@ -68,24 +54,6 @@ public fun interface At { */ public fun Optional.at(i: I): Optional = this.compose(this@At.at(i)) - /** - * DSL to compose [At] with a [Getter] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Getter] with a focus in [S] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Getter] with a focus in [A] at given index [I]. - */ - public fun Getter.at(i: I): Getter = this.compose(this@At.at(i)) - - /** - * DSL to compose [At] with a [Setter] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Setter] with a focus in [S] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Setter] with a focus in [A] at given index [I]. - */ - public fun Setter.at(i: I): Setter = this.compose(this@At.at(i)) - /** * DSL to compose [At] with a [Traversal] for a structure [S] to focus in on [A] at given index [I]. * @@ -95,27 +63,8 @@ public fun interface At { */ public fun Traversal.at(i: I): Traversal = this.compose(this@At.at(i)) - /** - * DSL to compose [At] with a [Fold] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Fold] with a focus in [S] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Fold] with a focus in [A] at given index [I]. - */ - public fun Fold.at(i: I): Fold = this.compose(this@At.at(i)) - public companion object { - /** - * Lift an instance of [At] using an [Iso]. - * - * @param AT [At] that can provide [Lens] for a structure [U] with a focus in [A] with given index [I]. - * @param iso [Iso] that defines an isomorphism between [S] and [U] - * @return [At] to provide [Lens] for structure [S] with focus in [A] at given index [I] - */ - public fun fromIso(AT: At, iso: Iso): At = - At { i -> iso compose AT.at(i) } - @JvmStatic public fun map(): At, K, Option> = At { i -> diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt index 47883f600cc..7d14d5d36dc 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Cons.kt @@ -2,7 +2,6 @@ package arrow.optics.typeclasses import arrow.core.left import arrow.core.right -import arrow.optics.Iso import arrow.optics.Optional import arrow.optics.PLens import arrow.optics.PPrism @@ -53,12 +52,6 @@ public fun interface Cons { public companion object { - /** - * Lift an instance of [Cons] using an [Iso]. - */ - public fun fromIso(C: Cons, iso: Iso): Cons = - Cons { iso compose C.cons() compose iso.reverse().second() } - public operator fun invoke(prism: Prism>): Cons = Cons { prism } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt index 1f228612a88..4dd0099d548 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/FilterIndex.kt @@ -4,7 +4,7 @@ import arrow.core.NonEmptyList import arrow.core.Predicate import arrow.core.toNonEmptyListOrNull import arrow.optics.Every -import arrow.optics.Iso +import arrow.optics.PLens import arrow.optics.Traversal import arrow.typeclasses.Monoid import kotlin.jvm.JvmStatic @@ -25,12 +25,6 @@ public fun interface FilterIndex { public companion object { - /** - * Lift an instance of [FilterIndex] using an [Iso] - */ - public fun fromIso(FI: FilterIndex, iso: Iso): FilterIndex = - FilterIndex { p -> iso compose FI.filter(p) } - /** * [FilterIndex] instance definition for [List]. */ @@ -106,7 +100,7 @@ public fun interface FilterIndex { @JvmStatic public fun string(): FilterIndex = FilterIndex { p -> - Iso.stringToList() compose list().filter(p) + PLens.stringToList() compose list().filter(p) } } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt index 1bf929f59e6..63b2325b354 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt @@ -4,13 +4,11 @@ import arrow.core.NonEmptyList import arrow.core.left import arrow.core.right import arrow.core.toNonEmptyListOrNull -import arrow.optics.Fold -import arrow.optics.Iso import arrow.optics.Lens import arrow.optics.Optional +import arrow.optics.PLens import arrow.optics.POptional import arrow.optics.Prism -import arrow.optics.Setter import arrow.optics.Traversal import kotlin.jvm.JvmStatic @@ -40,15 +38,6 @@ public fun interface Index { */ public fun Lens.index(i: I): Optional = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with an [Iso] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Iso] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public fun Iso.index(i: I): Optional = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. * @@ -67,15 +56,6 @@ public fun interface Index { */ public fun Optional.index(i: I): Optional = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with a [Setter] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Setter] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Setter] with a focus in [A] at given index [I]. - */ - public fun Setter.index(i: I): Setter = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with a [Traversal] for a structure [S] to focus in on [A] at given index [I]. * @@ -85,15 +65,6 @@ public fun interface Index { */ public fun Traversal.index(i: I): Traversal = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with a [Fold] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Fold] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Fold] with a focus in [A] at given index [I]. - */ - public fun Fold.index(i: I): Fold = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with a [Lens] for a structure [S] to focus in on [A] at given index [I]. * @@ -103,15 +74,6 @@ public fun interface Index { */ public operator fun Lens.get(i: I): Optional = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with an [Iso] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Iso] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public operator fun Iso.get(i: I): Optional = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. * @@ -130,15 +92,6 @@ public fun interface Index { */ public operator fun Optional.get(i: I): Optional = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with a [Setter] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Setter] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Setter] with a focus in [A] at given index [I]. - */ - public operator fun Setter.get(i: I): Setter = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with a [Traversal] for a structure [S] to focus in on [A] at given index [I]. * @@ -148,25 +101,7 @@ public fun interface Index { */ public operator fun Traversal.get(i: I): Traversal = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with a [Fold] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Fold] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Fold] with a focus in [A] at given index [I]. - */ - public operator fun Fold.get(i: I): Fold = this.compose(this@Index.index(i)) - public companion object { - /** - * Lift an instance of [Index] using an [Iso]. - * - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] - * @param iso [Iso] that defines an isomorphism between a type [S] and [A] - * @return [Index] for a structure [S] to focus in an optional [A] at a given index [I] - */ - public fun fromIso(ID: Index, iso: Iso): Index = - Index { i -> iso compose ID.index(i) } /** * [Index] instance definition for [List]. @@ -224,7 +159,7 @@ public fun interface Index { @JvmStatic public fun string(): Index = Index { i -> - Iso.stringToList() compose Index.list().index(i) + PLens.stringToList() compose Index.list().index(i) } } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt index 92bedbd7bce..125d64834b3 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Snoc.kt @@ -4,7 +4,6 @@ import arrow.core.Either import arrow.core.Nullable import arrow.core.left import arrow.core.right -import arrow.optics.Iso import arrow.optics.Optional import arrow.optics.PLens import arrow.optics.Prism @@ -56,12 +55,6 @@ public fun interface Snoc { public companion object { - /** - * Lift an instance of [Snoc] using an [Iso]. - */ - public fun fromIso(SS: Snoc, iso: Iso): Snoc = - Snoc { iso compose SS.snoc() compose iso.reverse().first() } - /** * Construct a [Snoc] instance from a [Prism]. */ diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/FoldTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/FoldTest.kt deleted file mode 100644 index f7ccc662213..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/FoldTest.kt +++ /dev/null @@ -1,89 +0,0 @@ -package arrow.optics - -import arrow.core.test.UnitSpec -import arrow.typeclasses.Monoid -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.orNull - -class FoldTest : UnitSpec() { - - init { - - "Fold select a list that contains one" { - val select = Fold.select> { it.contains(1) } - - checkAll(Arb.list(Arb.int())) { ints -> - select.run { getAll(ints) }.firstOrNull() shouldBe - ints.let { if (it.contains(1)) it else null } - } - } - - with(Fold.list()) { - - "Folding a list of ints" { - checkAll(Arb.list(Arb.int())) { ints -> - fold(Monoid.int(), ints) shouldBe ints.sum() - } - } - - "Folding a list should yield same result as combineAll" { - checkAll(Arb.list(Arb.int())) { ints -> - combineAll(Monoid.int(), ints) shouldBe ints.sum() - } - } - - "Folding and mapping a list of strings" { - checkAll(Arb.list(Arb.int())) { ints -> - Fold.list() - .foldMap(Monoid.int(), ints.map(Int::toString), String::toInt) shouldBe ints.sum() - } - } - - "Get all targets" { - checkAll(Arb.list(Arb.int())) { ints -> - getAll(ints) shouldBe ints - } - } - - "Get the size of the fold" { - checkAll(Arb.list(Arb.int())) { ints -> - size(ints) shouldBe ints.size - } - } - - "Find the first element matching the predicate" { - checkAll(Arb.list(Arb.int(-100..100).orNull())) { ints -> - val predicate = { i: Int? -> i?.let { it > 10 } ?: false } - Fold.list().findOrNull(ints, predicate) shouldBe ints.firstOrNull(predicate) - } - } - - "Checking existence of a target" { - checkAll(Arb.list(Arb.int().orNull()), Arb.boolean()) { ints, predicate -> - Fold.list().exists(ints) { predicate } shouldBe (predicate && ints.isNotEmpty()) - } - } - - "Check if all targets match the predicate" { - checkAll(Arb.list(Arb.int())) { ints -> - all(ints) { it % 2 == 0 } shouldBe ints.all { it % 2 == 0 } - } - } - - "Check if there is no target" { - checkAll(Arb.list(Arb.int())) { ints -> - isEmpty(ints) shouldBe ints.isEmpty() - } - } - - "Check if there is a target" { - checkAll(Arb.list(Arb.int())) { ints -> - isNotEmpty(ints) shouldBe ints.isNotEmpty() - } - } - } - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/GetterTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/GetterTest.kt deleted file mode 100644 index 98cc17e6a49..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/GetterTest.kt +++ /dev/null @@ -1,121 +0,0 @@ -package arrow.optics - -import arrow.core.Either.Left -import arrow.core.Either.Right -import arrow.core.test.UnitSpec -import arrow.typeclasses.Monoid -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string -import io.kotest.property.arbitrary.boolean - -class GetterTest : UnitSpec() { - - init { - - "asFold should behave as valid Fold: size" { - checkAll(Arb.token()) { token -> - Getter.token().size(token) shouldBe 1 - } - } - - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.token()) { token -> - Getter.token().isNotEmpty(token) shouldBe true - } - } - - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.token()) { token -> - !Getter.token().isEmpty(token) shouldBe true - } - } - - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.token()) { token -> - Getter.token().getAll(token) shouldBe listOf(token.value) - } - } - - "asFold should behave as valid Fold: combineAll" { - checkAll(Arb.token()) { token -> - Getter.token().combineAll(Monoid.string(), token) shouldBe token.value - } - } - - "asFold should behave as valid Fold: fold" { - checkAll(Arb.token()) { token -> - Getter.token().fold(Monoid.string(), token) shouldBe token.value - } - } - - "asFold should behave as valid Fold: headOption" { - checkAll(Arb.token()) { token -> - Getter.token().firstOrNull(token) shouldBe token.value - } - } - - "asFold should behave as valid Fold: lastOption" { - checkAll(Arb.token()) { token -> - Getter.token().lastOrNull(token) shouldBe token.value - } - } - - "Getting the target should always yield the exact result" { - checkAll(Arb.string()) { value: String -> - Getter.token().get(Token(value)) shouldBe value - } - } - - "Finding a target using a predicate within a Getter should be wrapped in the correct option result" { - checkAll(Arb.string(), Arb.boolean()) { value: String, predicate: Boolean -> - Getter.token().findOrNull(Token(value)) { predicate }?.let { true } ?: false shouldBe predicate - } - } - - "Checking existence of a target should always result in the same result as predicate" { - checkAll(Arb.string(), Arb.boolean()) { value: String, predicate: Boolean -> - Getter.token().any(Token(value)) { predicate } shouldBe predicate - } - } - - "Zipping two lenses should yield a tuple of the targets" { - checkAll(Arb.string()) { value: String -> - Getter { it.length }.zip { it.uppercase() } - .get(value) shouldBe (value.length to value.toUpperCase()) - } - } - - "Joining two getters together with same target should yield same result" { - checkAll(Arb.string()) { tokenValue: String -> - val userTokenStringGetter = Iso.user() compose Getter.token() - val joinedGetter = Getter.token().choice(userTokenStringGetter) - val token = Token(tokenValue) - val user = User(token) - joinedGetter.get(Left(token)) shouldBe joinedGetter.get(Right(user)) - } - } - - "Pairing two disjoint getters should yield a pair of their results" { - val splitGetter: Getter, Pair> = Getter.token().split(Iso.user()) - checkAll(Arb.token(), Arb.user()) { token: Token, user: User -> - splitGetter.get(token to user) shouldBe (token.value to user.token) - } - } - - "Creating a first pair with a type should result in the target to value" { - val first = Getter.token().first() - checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> - first.get(token to int) shouldBe (token.value to int) - } - } - - "Creating a second pair with a type should result in the value target" { - checkAll(Arb.int(), Arb.token()) { int: Int, token: Token -> - val first = Getter.token().second() - first.get(int to token) shouldBe (int to token.value) - } - } - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt deleted file mode 100644 index 6c290dbc442..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/IsoTest.kt +++ /dev/null @@ -1,213 +0,0 @@ -package arrow.optics - -import arrow.core.Either -import arrow.core.test.UnitSpec -import arrow.core.test.generators.functionAToB -import arrow.optics.test.laws.IsoLaws -import arrow.optics.test.laws.LensLaws -import arrow.optics.test.laws.OptionalLaws -import arrow.optics.test.laws.PrismLaws -import arrow.optics.test.laws.SetterLaws -import arrow.optics.test.laws.TraversalLaws -import arrow.typeclasses.Monoid -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string - -class IsoTest : UnitSpec() { - - init { - - val aIso: Iso = Iso( - get = { a: SumType.A -> a.string }, - reverseGet = SumType::A - ) - - testLaws( - "Iso token - ", - LensLaws.laws( - lens = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - PrismLaws.laws( - prism = aIso, - aGen = Arb.sumTypeA(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - TraversalLaws.laws( - traversal = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - OptionalLaws.laws( - optional = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - SetterLaws.laws( - setter = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ), - - IsoLaws.laws( - iso = Iso.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()) - ) - ) - - with(Iso.token()) { - - "asFold should behave as valid Fold: size" { - checkAll(Arb.token()) { token -> - size(token) shouldBe 1 - } - } - - "asFold should behave as valid Fold: nonEmpty" { - checkAll(Arb.token()) { token -> - isNotEmpty(token) shouldBe true - } - } - - "asFold should behave as valid Fold: isEmpty" { - checkAll(Arb.token()) { token -> - !isEmpty(token) shouldBe true - } - } - - "asFold should behave as valid Fold: getAll" { - checkAll(Arb.token()) { token -> - getAll(token) shouldBe listOf(token.value) - } - } - - "asFold should behave as valid Fold: combineAll" { - checkAll(Arb.token()) { token -> - combineAll(Monoid.string(), token) shouldBe token.value - } - } - - "asFold should behave as valid Fold: fold" { - checkAll(Arb.token()) { token -> - fold(Monoid.string(), token) shouldBe token.value - } - } - - "asFold should behave as valid Fold: headOption" { - checkAll(Arb.token()) { token -> - firstOrNull(token) shouldBe token.value - } - } - - "asFold should behave as valid Fold: lastOption" { - checkAll(Arb.token()) { token -> - lastOrNull(token) shouldBe token.value - } - } - } - - with(Iso.token()) { - - "asGetter should behave as valid Getter: get" { - checkAll(Arb.token()) { token -> - get(token) shouldBe Getter.token().get(token) - } - } - - "asGetter should behave as valid Getter: find" { - checkAll(Arb.token(), Arb.functionAToB(Arb.boolean())) { token, p -> - findOrNull(token, p) shouldBe Getter.token().findOrNull(token, p) - } - } - - "asGetter should behave as valid Getter: exist" { - checkAll(Arb.token(), Arb.functionAToB(Arb.boolean())) { token, p -> - any(token, p) shouldBe Getter.token().any(token, p) - } - } - } - - "Lifting a function should yield the same result as not yielding" { - checkAll(Arb.token(), Arb.string()) { token, value -> - Iso.token().modify(token) { value } shouldBe Iso.token().lift { value }(token) - } - } - - "Creating a first pair with a type should result in the target to value" { - val first = Iso.token().first() - checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> - first.get(token to int) shouldBe (token.value to int) - } - } - - "Creating a second pair with a type should result in the value to target" { - val second = Iso.token().second() - checkAll(Arb.int(), Arb.token()) { int: Int, token: Token -> - second.get(int to token) shouldBe (int to token.value) - } - } - - "Creating a left with a type should result in a sum target to value" { - val left = Iso.token().left() - checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> - left.get(Either.Left(token)) shouldBe Either.Left(token.value) - left.get(Either.Right(int)) shouldBe Either.Right(int) - } - } - - "Creating a right with a type should result in a sum value to target" { - val left = Iso.token().right() - checkAll(Arb.token(), Arb.int()) { token: Token, int: Int -> - left.get(Either.Left(int)) shouldBe Either.Left(int) - left.get(Either.Right(token)) shouldBe Either.Right(token.value) - } - } - - "Finding a target using a predicate within a Iso should be wrapped in the correct option result" { - checkAll(Arb.boolean()) { predicate: Boolean -> - Iso.token().findOrNull(Token("any value")) { predicate }?.let { true } ?: false shouldBe predicate - } - } - - "Checking existence predicate over the target should result in same result as predicate" { - checkAll(Arb.boolean()) { predicate: Boolean -> - Iso.token().any(Token("any value")) { predicate } shouldBe predicate - } - } - - "Pairing two disjoint isos together" { - val joinedIso = Iso.token() split Iso.user() - - checkAll(Arb.string()) { tokenValue: String -> - val token = Token(tokenValue) - val user = User(token) - joinedIso.get(token to user) shouldBe (tokenValue to token) - } - } - - "Composing isos should result in an iso of the first iso's value with the second iso's target" { - val composedIso = Iso.user() compose Iso.token() - - checkAll(Arb.string()) { tokenValue: String -> - val token = Token(tokenValue) - val user = User(token) - composedIso.get(user) shouldBe tokenValue - } - } - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt index 749b89663ac..b6fd9931edb 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/LensTest.kt @@ -6,7 +6,6 @@ import arrow.core.test.UnitSpec import arrow.core.test.generators.functionAToB import arrow.optics.test.laws.LensLaws import arrow.optics.test.laws.OptionalLaws -import arrow.optics.test.laws.SetterLaws import arrow.optics.test.laws.TraversalLaws import arrow.typeclasses.Monoid import io.kotest.matchers.shouldBe @@ -40,13 +39,6 @@ class LensTest : UnitSpec() { bGen = Arb.string(), funcGen = Arb.functionAToB(Arb.string()), ), - - SetterLaws.laws( - setter = Lens.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()), - ) ) testLaws( @@ -107,24 +99,6 @@ class LensTest : UnitSpec() { } } - "asGetter should behave as valid Getter: get" { - checkAll(Arb.token()) { token -> - Lens.token().get(token) shouldBe Getter.token().get(token) - } - } - - "asGetter should behave as valid Getter: find" { - checkAll(Arb.token(), Arb.functionAToB(Arb.boolean())) { token, p -> - Lens.token().findOrNull(token, p) shouldBe Getter.token().findOrNull(token, p) - } - } - - "asGetter should behave as valid Getter: exist" { - checkAll(Arb.token(), Arb.functionAToB(Arb.boolean())) { token, p -> - Lens.token().any(token, p) shouldBe Getter.token().any(token, p) - } - } - "Lifting a function should yield the same result as not yielding" { checkAll(Arb.token(), Arb.string()) { token, value -> Lens.token().set(token, value) shouldBe Lens.token().lift { value }(token) diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalGetterTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalGetterTest.kt deleted file mode 100644 index 6a3fc8ef29b..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/OptionalGetterTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package arrow.optics - -import arrow.core.test.UnitSpec -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.boolean -import io.kotest.property.arbitrary.int - -class OptionalGetterTest : UnitSpec() { - - init { - "get should return value if predicate is true and null if otherwise" { - checkAll(Arb.int(), Arb.boolean()) { int, predicate -> - OptionalGetter.filter { predicate }.getOrNull(int) shouldBe (if (predicate) int else null) - } - } - - "getAll should return the old list if predicate is true" { - checkAll(Arb.list(Arb.int()), Arb.boolean()) { list, predicate -> - (Fold.list() compose OptionalGetter.filter { predicate }).getAll(list) shouldBe (if (predicate) list else emptyList()) - } - } - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt index 8d0f60cba95..0748cf069e7 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/PrismTest.kt @@ -5,7 +5,6 @@ import arrow.core.test.generators.either import arrow.core.test.generators.functionAToB import arrow.optics.test.laws.OptionalLaws import arrow.optics.test.laws.PrismLaws -import arrow.optics.test.laws.SetterLaws import arrow.optics.test.laws.TraversalLaws import arrow.typeclasses.Monoid import io.kotest.matchers.shouldBe @@ -27,13 +26,6 @@ class PrismTest : UnitSpec() { funcGen = Arb.functionAToB(Arb.string()), ), - SetterLaws.laws( - setter = Prism.sumType(), - aGen = Arb.sumType(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()), - ), - TraversalLaws.laws( traversal = Prism.sumType(), aGen = Arb.sumType(), diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/SetterTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/SetterTest.kt deleted file mode 100644 index 3fc27061c0d..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/SetterTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -package arrow.optics - -import arrow.core.getOrElse -import arrow.core.left -import arrow.core.right -import arrow.core.test.UnitSpec -import arrow.core.test.generators.functionAToB -import arrow.optics.test.laws.SetterLaws -import io.kotest.matchers.shouldBe -import io.kotest.property.Arb -import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.string - -class SetterTest : UnitSpec() { - - init { - - testLaws( - "Setter identity - ", - SetterLaws.laws( - setter = Setter.id(), - aGen = Arb.int(), - bGen = Arb.int(), - funcGen = Arb.functionAToB(Arb.int()), - ) - ) - - testLaws( - "Setter token - ", - SetterLaws.laws( - setter = Setter.token(), - aGen = Arb.token(), - bGen = Arb.string(), - funcGen = Arb.functionAToB(Arb.string()), - ) - ) - - "Joining two lenses together with same target should yield same result" { - val userTokenStringSetter = Setter.user() compose Setter.token() - val joinedSetter = Setter.token().choice(userTokenStringSetter) - val oldValue = "oldValue" - val token = Token(oldValue) - val user = User(token) - - checkAll(Arb.string()) { value: String -> - joinedSetter.set(token.left(), value).swap().getOrElse { Token("Wrong value") }.value shouldBe - joinedSetter.set(user.right(), value).getOrElse { User(Token("Wrong value")) }.token.value - } - } - - "Lifting a function should yield the same result as direct modify" { - checkAll(Arb.token(), Arb.string()) { token, value -> - Setter.token().modify(token) { value } shouldBe Setter.token().lift { value }(token) - } - } - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt index 9bf599d1472..d861c59f0f9 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TestDomain.kt @@ -37,24 +37,11 @@ internal fun PLens.Companion.token(): Lens = PLens( { token: Token, value: String -> token.copy(value = value) } ) -internal fun PIso.Companion.token(): Iso = Iso( - { token: Token -> token.value }, - ::Token -) - -internal fun PSetter.Companion.token(): Setter = Setter { token, s -> - token.copy(value = s(token.value)) -} - -internal fun PIso.Companion.user(): Iso = Iso( +internal fun PLens.Companion.user(): Lens = PLens( { user: User -> user.token }, - ::User + { user: User, token: Token -> user.copy(token = token) } ) -internal fun PSetter.Companion.user(): Setter = Setter { user, s -> - user.copy(token = s(user.token)) -} - internal data class Token(val value: String) { companion object } @@ -71,14 +58,6 @@ internal data class IncompleteUser(val token: Token?) internal fun Arb.Companion.incompleteUser(): Arb = Arb.constant(IncompleteUser(null)) -internal fun PGetter.Companion.token(): Getter = - Getter { it.value } - -internal fun PLens.Companion.user(): Lens = Lens( - { user: User -> user.token }, - { user: User, token: Token -> user.copy(token = token) } -) - internal fun POptional.Companion.incompleteUserToken(): Optional = Optional( getOrModify = { user -> user.token?.right() ?: user.left() }, set = { user, token -> user.copy(token = token) } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt index d93b5e0eb44..f27baf70de5 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/TraversalTest.kt @@ -3,7 +3,6 @@ package arrow.optics import arrow.core.test.UnitSpec import arrow.core.test.generators.functionAToB import arrow.core.test.generators.option -import arrow.optics.test.laws.SetterLaws import arrow.optics.test.laws.TraversalLaws import io.kotest.property.Arb import io.kotest.property.arbitrary.char @@ -22,13 +21,6 @@ class TraversalTest : UnitSpec() { bGen = Arb.int(), funcGen = Arb.functionAToB(Arb.int()), ), - - SetterLaws.laws( - setter = Traversal.list(), - aGen = Arb.list(Arb.int()), - bGen = Arb.int(), - funcGen = Arb.functionAToB(Arb.int()), - ) ) testLaws( diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt index 43313bfb6df..c5684f04b4d 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/instances/ConsInstanceTest.kt @@ -7,7 +7,6 @@ import arrow.optics.typeclasses.Cons import io.kotest.property.Arb import io.kotest.property.arbitrary.char import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.pair import io.kotest.property.arbitrary.string diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt index e5e3ff35748..ca4d631872a 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/ListTest.kt @@ -2,12 +2,8 @@ package arrow.optics.std import arrow.core.test.UnitSpec import arrow.core.test.generators.functionAToB -import arrow.core.test.generators.option -import arrow.optics.Iso import arrow.optics.Optional -import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.OptionalLaws -import arrow.optics.test.laws.SetterLaws import arrow.optics.test.laws.TraversalLaws import io.kotest.property.Arb import io.kotest.property.arbitrary.int @@ -30,12 +26,6 @@ class ListTest : UnitSpec() { bGen = Arb.int(), funcGen = Arb.functionAToB(Arb.int()), ), - SetterLaws.laws( - setter = Optional.listHead(), - aGen = Arb.list(Arb.int()), - bGen = Arb.int(), - funcGen = Arb.functionAToB(Arb.int()), - ) ) testLaws( @@ -47,15 +37,5 @@ class ListTest : UnitSpec() { funcGen = Arb.functionAToB(Arb.list(Arb.int())), ) ) - - testLaws( - "Iso list to Option Nel - ", - IsoLaws.laws( - iso = Iso.listToOptionNel(), - aGen = Arb.list(Arb.int()), - bGen = Arb.option(Arb.nonEmptyList(Arb.int())), - funcGen = Arb.functionAToB(Arb.option(Arb.nonEmptyList(Arb.int()))), - ) - ) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt deleted file mode 100644 index 3f3c373a089..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/MapTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -package arrow.optics.std - -import arrow.core.test.UnitSpec -import arrow.core.test.generators.functionAToB -import arrow.optics.Iso -import arrow.optics.test.laws.IsoLaws -import io.kotest.property.Arb -import io.kotest.property.arbitrary.constant -import io.kotest.property.arbitrary.set -import io.kotest.property.arbitrary.string - -class MapTest : UnitSpec() { - - init { - testLaws( - IsoLaws.laws( - iso = Iso.mapToSet(), - aGen = Arb.map(Arb.string(), Arb.constant(Unit)), - bGen = Arb.set(Arb.string()), - funcGen = Arb.functionAToB(Arb.set(Arb.string())), - ) - ) - } -} diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt index 218843b27ac..ec4301026ca 100644 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/OptionTest.kt @@ -4,9 +4,7 @@ import arrow.core.test.UnitSpec import arrow.core.test.generators.either import arrow.core.test.generators.functionAToB import arrow.core.test.generators.option -import arrow.optics.Iso import arrow.optics.Prism -import arrow.optics.test.laws.IsoLaws import arrow.optics.test.laws.PrismLaws import io.kotest.property.Arb import io.kotest.property.arbitrary.constant @@ -36,25 +34,5 @@ class OptionTest : UnitSpec() { funcGen = Arb.functionAToB(Arb.constant(Unit)), ) ) - - testLaws( - "Iso option to nullable - ", - IsoLaws.laws( - iso = Iso.optionToNullable().reverse(), - aGen = Arb.int().orNull(), - bGen = Arb.option(Arb.int()), - funcGen = Arb.functionAToB(Arb.option(Arb.int())) - ) - ) - - testLaws( - "Iso option to either - ", - IsoLaws.laws( - iso = Iso.optionToEither(), - aGen = Arb.option(Arb.int()), - bGen = Arb.either(Arb.constant(Unit), Arb.int()), - funcGen = Arb.functionAToB(Arb.either(Arb.constant(Unit), Arb.int())), - ) - ) } } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt deleted file mode 100644 index 2bbc8658213..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/arrow/optics/std/StringTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -package arrow.optics.std - -import arrow.core.test.UnitSpec -import arrow.optics.Iso -import arrow.optics.test.laws.IsoLaws -import io.kotest.property.Arb -import io.kotest.property.arbitrary.char -import io.kotest.property.arbitrary.list -import io.kotest.property.arbitrary.map -import io.kotest.property.arbitrary.string - -class StringTest : UnitSpec() { - - init { - - testLaws( - "Iso string to list - ", - IsoLaws.laws( - iso = Iso.stringToList(), - aGen = Arb.string(), - bGen = Arb.list(Arb.char()), - funcGen = Arb.list(Arb.char()).map { list -> { chars: List -> list + chars } }, - ) - ) - } -} From b75167f20c13a76639737b09263cdf91d37d6b38 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 15 Dec 2022 13:16:32 +0100 Subject: [PATCH 07/11] Remove KSP generation for Iso & Optional --- .../arrow/optics/plugin/internals/domain.kt | 66 ++----------- .../arrow/optics/plugin/internals/dsl.kt | 59 ----------- .../arrow/optics/plugin/internals/errors.kt | 42 -------- .../arrow/optics/plugin/internals/isos.kt | 80 --------------- .../arrow/optics/plugin/internals/lenses.kt | 20 +--- .../arrow/optics/plugin/internals/optional.kt | 52 ---------- .../arrow/optics/plugin/internals/prism.kt | 2 - .../optics/plugin/internals/processor.kt | 43 +------- .../arrow/optics/plugin/internals/snippets.kt | 4 +- .../kotlin/arrow/optics/plugin/DSLTests.kt | 2 +- .../kotlin/arrow/optics/plugin/IsoTests.kt | 97 ------------------- .../arrow/optics/plugin/OptionalTests.kt | 15 +-- .../main/kotlin/arrow/optics/Reflection.kt | 8 +- .../kotlin/arrow/optics/ReflectionTest.kt | 8 -- .../kotlin/arrow/optics/Optional.kt | 9 ++ .../commonMain/kotlin/arrow/optics/Prism.kt | 20 ++-- .../commonMain/kotlin/arrow/optics/dsl/at.kt | 24 ++--- .../kotlin/arrow/optics/dsl/every.kt | 34 +------ .../kotlin/arrow/optics/dsl/index.kt | 24 ++--- .../kotlin/arrow/optics/dsl/nullable.kt | 23 +++++ .../kotlin/arrow/optics/dsl/option.kt | 19 +--- .../commonMain/kotlin/arrow/optics/predef.kt | 2 +- .../kotlin/arrow/optics/typeclasses/At.kt | 10 -- .../kotlin/arrow/optics/typeclasses/Index.kt | 40 +------- .../kotlin/examples/example-optional-01.kt | 23 ----- 25 files changed, 88 insertions(+), 638 deletions(-) delete mode 100644 arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/isos.kt delete mode 100644 arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/optional.kt delete mode 100755 arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt create mode 100644 arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/nullable.kt delete mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt index 6960a675805..070d410dd09 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/domain.kt @@ -31,21 +31,15 @@ val KSClassDeclaration.nameWithParentClass: String } enum class OpticsTarget { - ISO, LENS, PRISM, - OPTIONAL, DSL } -typealias IsoTarget = Target.Iso - typealias PrismTarget = Target.Prism typealias LensTarget = Target.Lens -typealias OptionalTarget = Target.Optional - typealias SealedClassDsl = Target.SealedClassDsl typealias DataClassDsl = Target.DataClassDsl @@ -53,76 +47,32 @@ typealias DataClassDsl = Target.DataClassDsl sealed class Target { abstract val foci: List - data class Iso(override val foci: List) : Target() data class Prism(override val foci: List) : Target() data class Lens(override val foci: List) : Target() - data class Optional(override val foci: List) : Target() data class SealedClassDsl(override val foci: List) : Target() data class DataClassDsl(override val foci: List) : Target() } -typealias NonNullFocus = Focus.NonNull - -typealias OptionFocus = Focus.Option - -typealias NullableFocus = Focus.Nullable - -sealed class Focus { - - companion object { - operator fun invoke(fullName: String, paramName: String, refinedType: KSType? = null): Focus = - when { - fullName.endsWith("?") -> Nullable(fullName, paramName, refinedType) - fullName.startsWith("`arrow`.`core`.`Option`") -> Option(fullName, paramName, refinedType) - else -> NonNull(fullName, paramName, refinedType) - } - } - - abstract val className: String - abstract val paramName: String - // only used for type-refining prisms - abstract val refinedType: KSType? - +data class Focus( + val className: String, + val paramName: String, + val refinedType: KSType? +) { val refinedArguments: List get() = refinedType?.arguments?.filter { it.type?.resolve()?.declaration is KSTypeParameter }?.map { it.qualifiedString() }.orEmpty() - data class Nullable( - override val className: String, - override val paramName: String, - override val refinedType: KSType? - ) : Focus() { - val nonNullClassName = className.dropLast(1) - } - - data class Option( - override val className: String, - override val paramName: String, - override val refinedType: KSType? - ) : Focus() { - val nestedClassName = - Regex("`arrow`.`core`.`Option`<(.*)>$").matchEntire(className)!!.groupValues[1] + companion object { + operator fun invoke(fullName: String, paramName: String): Focus = + Focus(fullName, paramName, null) } - - data class NonNull( - override val className: String, - override val paramName: String, - override val refinedType: KSType? - ) : Focus() } const val Lens = "arrow.optics.Lens" -const val Iso = "arrow.optics.Iso" const val Optional = "arrow.optics.Optional" const val Prism = "arrow.optics.Prism" -const val Getter = "arrow.optics.Getter" -const val Setter = "arrow.optics.Setter" const val Traversal = "arrow.optics.Traversal" -const val Fold = "arrow.optics.Fold" -const val Tuple = "arrow.core.Tuple" -const val Pair = "kotlin.Pair" -const val Triple = "kotlin.Triple" data class Snippet( val `package`: String, diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt index 6a1abfc40d6..250fbb4d922 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/dsl.kt @@ -7,13 +7,6 @@ fun generateLensDsl(ele: ADT, optic: DataClassDsl): Snippet = content = processLensSyntax(ele, optic.foci) ) -fun generateOptionalDsl(ele: ADT, optic: DataClassDsl): Snippet = - Snippet( - `package` = ele.packageName, - name = ele.simpleName, - content = processOptionalSyntax(ele, optic) - ) - fun generatePrismDsl(ele: ADT, isoOptic: SealedClassDsl): Snippet = Snippet( `package` = ele.packageName, @@ -25,14 +18,9 @@ private fun processLensSyntax(ele: ADT, foci: List): String = if (ele.typeParameters.isEmpty()) { foci.joinToString(separator = "\n") { focus -> """ - |${ele.visibilityModifierName} inline val $Iso.${focus.lensParamName()}: $Lens inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |${ele.visibilityModifierName} inline val $Lens.${focus.lensParamName()}: $Lens inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |${ele.visibilityModifierName} inline val $Optional.${focus.lensParamName()}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} - |${ele.visibilityModifierName} inline val $Prism.${focus.lensParamName()}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} - |${ele.visibilityModifierName} inline val $Getter.${focus.lensParamName()}: $Getter inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} - |${ele.visibilityModifierName} inline val $Setter.${focus.lensParamName()}: $Setter inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |${ele.visibilityModifierName} inline val $Traversal.${focus.lensParamName()}: $Traversal inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} - |${ele.visibilityModifierName} inline val $Fold.${focus.lensParamName()}: $Fold inline get() = this + ${ele.sourceClassName}.${focus.lensParamName()} |""".trimMargin() } } else { @@ -40,63 +28,20 @@ private fun processLensSyntax(ele: ADT, foci: List): String = val joinedTypeParams = ele.typeParameters.joinToString(separator=",") foci.joinToString(separator = "\n") { focus -> """ - |${ele.visibilityModifierName} inline fun $Iso.${focus.lensParamName()}(): $Lens = this + ${ele.sourceClassName}.${focus.lensParamName()}() |${ele.visibilityModifierName} inline fun $Lens.${focus.lensParamName()}(): $Lens = this + ${ele.sourceClassName}.${focus.lensParamName()}() |${ele.visibilityModifierName} inline fun $Optional.${focus.lensParamName()}(): $Optional = this + ${ele.sourceClassName}.${focus.lensParamName()}() - |${ele.visibilityModifierName} inline fun $Prism.${focus.lensParamName()}(): $Optional = this + ${ele.sourceClassName}.${focus.lensParamName()}() - |${ele.visibilityModifierName} inline fun $Getter.${focus.lensParamName()}(): $Getter = this + ${ele.sourceClassName}.${focus.lensParamName()}() - |${ele.visibilityModifierName} inline fun $Setter.${focus.lensParamName()}(): $Setter = this + ${ele.sourceClassName}.${focus.lensParamName()}() |${ele.visibilityModifierName} inline fun $Traversal.${focus.lensParamName()}(): $Traversal = this + ${ele.sourceClassName}.${focus.lensParamName()}() - |${ele.visibilityModifierName} inline fun $Fold.${focus.lensParamName()}(): $Fold = this + ${ele.sourceClassName}.${focus.lensParamName()}() - |""".trimMargin() - } - } - -private fun processOptionalSyntax(ele: ADT, optic: DataClassDsl): String { - val sourceClassNameWithParams = "${ele.sourceClassName}${ele.angledTypeParameters}" - val joinedTypeParams = ele.typeParameters.joinToString(separator=",") - return optic.foci.filterNot { it is NonNullFocus }.joinToString(separator = "\n") { focus -> - val targetClassName = - when (focus) { - is Focus.Nullable -> focus.nonNullClassName - is Focus.Option -> focus.nestedClassName - is Focus.NonNull -> "" - } - if (ele.typeParameters.isEmpty()) { - """ - |${ele.visibilityModifierName} inline val $Iso.${focus.paramName}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Lens.${focus.paramName}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Optional.${focus.paramName}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Prism.${focus.paramName}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Setter.${focus.paramName}: $Setter inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Traversal.${focus.paramName}: $Traversal inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Fold.${focus.paramName}: $Fold inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |""".trimMargin() - } else { - """ - |${ele.visibilityModifierName} inline fun $Iso.${focus.paramName}(): $Optional = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Lens.${focus.paramName}(): $Optional = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Optional.${focus.paramName}(): $Optional = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Prism.${focus.paramName}(): $Optional = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Setter.${focus.paramName}(): $Setter = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Traversal.${focus.paramName}(): $Traversal = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Fold.${focus.paramName}(): $Fold = this + ${ele.sourceClassName}.${focus.paramName}() |""".trimMargin() } } -} private fun processPrismSyntax(ele: ADT, dsl: SealedClassDsl): String = if (ele.typeParameters.isEmpty()) { dsl.foci.joinToString(separator = "\n\n") { focus -> """ - |${ele.visibilityModifierName} inline val $Iso.${focus.paramName}: $Prism inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Lens.${focus.paramName}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Optional.${focus.paramName}: $Optional inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Prism.${focus.paramName}: $Prism inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Setter.${focus.paramName}: $Setter inline get() = this + ${ele.sourceClassName}.${focus.paramName} |${ele.visibilityModifierName} inline val $Traversal.${focus.paramName}: $Traversal inline get() = this + ${ele.sourceClassName}.${focus.paramName} - |${ele.visibilityModifierName} inline val $Fold.${focus.paramName}: $Fold inline get() = this + ${ele.sourceClassName}.${focus.paramName} |""".trimMargin() } } else { @@ -107,13 +52,9 @@ private fun processPrismSyntax(ele: ADT, dsl: SealedClassDsl): String = else -> focus.refinedArguments.joinToString(separator=",") } """ - |${ele.visibilityModifierName} inline fun $Iso.${focus.paramName}(): $Prism = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Lens.${focus.paramName}(): $Optional = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Optional.${focus.paramName}(): $Optional = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Prism.${focus.paramName}(): $Prism = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Setter.${focus.paramName}(): $Setter = this + ${ele.sourceClassName}.${focus.paramName}() |${ele.visibilityModifierName} inline fun $Traversal.${focus.paramName}(): $Traversal = this + ${ele.sourceClassName}.${focus.paramName}() - |${ele.visibilityModifierName} inline fun $Fold.${focus.paramName}(): $Fold = this + ${ele.sourceClassName}.${focus.paramName}() |""".trimMargin() } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt index 1c9b65fd979..2de1dca9c9e 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/errors.kt @@ -7,13 +7,6 @@ val String.otherClassTypeErrorMessage | ^ |Only data and sealed classes can be annotated with @optics""".trimMargin() -val String.typeParametersErrorMessage - get() = - """ - |$this cannot be annotated with @optics - | ^ - |Only classes with no type parameters can be annotated with @optics""".trimMargin() - val String.lensErrorMessage get() = """ @@ -23,15 +16,6 @@ val String.lensErrorMessage |It is only valid for data classes. """.trimMargin() -val String.optionalErrorMessage - get() = - """ - |Cannot generate arrow.optics.Optional for $this - | ^ - |arrow.optics.OpticsTarget.OPTIONAL is an invalid @optics argument for $this. - |It is only valid for data classes. - """.trimMargin() - val String.prismErrorMessage get() = """ @@ -41,32 +25,6 @@ val String.prismErrorMessage |It is only valid for sealed classes. """.trimMargin() -val String.isoErrorMessage - get() = - """ - |Cannot generate arrow.optics.Iso for $this - | ^ - |arrow.optics.OpticsTarget.ISO is an invalid @optics argument for $this. - |It is only valid for data classes. - """.trimMargin() - -val String.isoTooBigErrorMessage - get() = - """ - |Cannot generate arrow.optics.Iso for $this - | ^ - |Iso generation is supported for data classes with up to 22 constructor parameters. - """.trimMargin() - -val String.dslErrorMessage - get() = - """ - |Cannot generate DSL (arrow.optics.BoundSetter) for $this - | ^ - |arrow.optics.OpticsTarget.DSL is an invalid @optics argument for $this. - |It is only valid for data classes and sealed classes. - """.trimMargin() - val String.noCompanion get() = """ diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/isos.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/isos.kt deleted file mode 100644 index dce33e5b3e0..00000000000 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/isos.kt +++ /dev/null @@ -1,80 +0,0 @@ -package arrow.optics.plugin.internals - -internal fun generateIsos(ele: ADT, target: IsoTarget) = - Snippet(`package` = ele.packageName, name = ele.simpleName, content = processElement(ele, target)) - -inline val Target.targetNames - inline get() = foci.map(Focus::className) - -private fun processElement(iso: ADT, target: Target): String { - val foci = target.foci - val letters = listOf( - "first", - "second", - "third", - "fourth", - "fifth", - "sixth", - "seventh", - "eighth", - "ninth", - "tenth", - "eleventh", - "twelfth", - "thirteenth", - "fourteenth", - "fifteenth", - "sixteenth", - "seventeenth", - "eighteenth", - "nineteenth", - "twentieth", - "twentyFirst", - "twentySecond" - ) - - fun Focus.format(): String = - "${iso.sourceName}.${paramName.plusIfNotBlank(prefix = "`", postfix = "`")}" - - fun tupleConstructor() = - when (foci.size) { - 1 -> "${iso.sourceName}.${foci.first().paramName}" - 2 -> "$Pair(${foci[0].format()}, ${foci[1].format()})" - 3 -> "$Triple(${foci[0].format()}, ${foci[1].format()}, ${foci[2].format()})" - else -> - foci.joinToString(prefix = "$Tuple${foci.size}(", postfix = ")", transform = Focus::format) - } - - fun focusType() = - when (foci.size) { - 1 -> target.targetNames.first() - 2 -> target.targetNames.joinToString(prefix = "$Pair<", postfix = ">") - 3 -> target.targetNames.joinToString(prefix = "$Triple<", postfix = ">") - else -> target.targetNames.joinToString(prefix = "$Tuple${foci.size}<", postfix = ">") - } - - fun classConstructorFromTuple() = - when (foci.size) { - 1 -> "${iso.sourceClassName}(it)" - 2 -> "pair: ${focusType()} -> ${iso.sourceClassName}(pair.first, pair.second)" - 3 -> - "triple: ${focusType()} -> ${iso.sourceClassName}(triple.first, triple.second, triple.third)" - else -> - "tuple: ${focusType()} -> ${(foci.indices).joinToString(prefix = "${iso.sourceClassName}(", postfix = ")", transform = { "tuple.${letters[it]}" })}" - } - - val sourceClassNameWithParams = "${iso.sourceClassName}${iso.angledTypeParameters}" - val firstLine = when { - iso.typeParameters.isEmpty() -> - "${iso.visibilityModifierName} inline val ${iso.sourceClassName}.Companion.iso: $Iso<${iso.sourceClassName}, ${focusType()}> inline get()" - else -> - "${iso.visibilityModifierName} inline fun ${iso.angledTypeParameters} ${iso.sourceClassName}.Companion.iso(): $Iso<$sourceClassNameWithParams, ${focusType()}>" - } - - return """ - |$firstLine = $Iso( - | get = { ${iso.sourceName}: $sourceClassNameWithParams -> ${tupleConstructor()} }, - | reverseGet = { ${classConstructorFromTuple()} } - |) - |""".trimMargin() -} diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/lenses.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/lenses.kt index 6b75addd841..82baef3b7c8 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/lenses.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/lenses.kt @@ -1,7 +1,5 @@ package arrow.optics.plugin.internals -import java.util.Locale - internal fun generateLenses(ele: ADT, target: LensTarget) = Snippet( `package` = ele.packageName, @@ -9,17 +7,6 @@ internal fun generateLenses(ele: ADT, target: LensTarget) = content = processElement(ele, target.foci) ) -private fun String.toUpperCamelCase(): String = - split(" ") - .joinToString( - "", - transform = { - it.replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() - } - } - ) - private fun processElement(adt: ADT, foci: List): String { val sourceClassNameWithParams = "${adt.sourceClassName}${adt.angledTypeParameters}" return foci.joinToString(separator = "\n") { focus -> @@ -48,9 +35,4 @@ private fun processElement(adt: ADT, foci: List): String { } } -fun Focus.lensParamName(): String = - when (this) { - is NullableFocus -> "nullable${paramName.toUpperCamelCase()}" - is OptionFocus -> "option${paramName.toUpperCamelCase()}" - is NonNullFocus -> paramName - } +fun Focus.lensParamName(): String = paramName diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/optional.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/optional.kt deleted file mode 100644 index 6a23c765d67..00000000000 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/optional.kt +++ /dev/null @@ -1,52 +0,0 @@ -package arrow.optics.plugin.internals - -internal fun generateOptionals(ele: ADT, target: OptionalTarget) = - Snippet( - `package` = ele.packageName, - name = ele.simpleName, - imports = - setOf("import arrow.core.left", "import arrow.core.right", "import arrow.core.toOption"), - content = processElement(ele, target.foci) - ) - -private fun processElement(ele: ADT, foci: List): String = - foci.joinToString(separator = "\n") { focus -> - - val targetClassName = when (focus) { - is NullableFocus -> focus.nonNullClassName - is OptionFocus -> focus.nestedClassName - is NonNullFocus -> return@joinToString "" - } - - val sourceClassNameWithParams = "${ele.sourceClassName}${ele.angledTypeParameters}" - val firstLine = when { - ele.typeParameters.isEmpty() -> - "${ele.visibilityModifierName} inline val ${ele.sourceClassName}.Companion.${focus.paramName}: $Optional<${ele.sourceClassName}, $targetClassName> inline get()" - else -> - "${ele.visibilityModifierName} inline fun ${ele.angledTypeParameters} ${ele.sourceClassName}.Companion.${focus.paramName}(): $Optional<$sourceClassNameWithParams, $targetClassName>" - } - - fun getOrModifyF(toNullable: String = "") = - "{ ${ele.sourceName}: $sourceClassNameWithParams -> ${ele.sourceName}.${ - focus.paramName.plusIfNotBlank( - prefix = "`", - postfix = "`" - ) - }$toNullable?.right() ?: ${ele.sourceName}.left() }" - fun setF(fromNullable: String = "") = - "${ele.sourceName}.copy(${focus.paramName.plusIfNotBlank(prefix = "`", postfix = "`")} = value$fromNullable)" - - val (getOrModify, set) = - when (focus) { - is NullableFocus -> Pair(getOrModifyF(), setF()) - is OptionFocus -> Pair(getOrModifyF(".orNull()"), setF(".toOption()")) - is NonNullFocus -> return@joinToString "" - } - - """ - |$firstLine = $Optional( - | getOrModify = $getOrModify, - | set = { ${ele.sourceName}: $sourceClassNameWithParams, value: $targetClassName -> $set } - |) - |""".trimMargin() - } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/prism.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/prism.kt index be20c59c6f0..f39f210827b 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/prism.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/prism.kt @@ -1,7 +1,5 @@ package arrow.optics.plugin.internals -import com.google.devtools.ksp.symbol.KSTypeParameter - internal fun generatePrisms(ele: ADT, target: PrismTarget) = Snippet( `package` = ele.packageName, diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index f3748303328..ee4b5496e78 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -15,10 +15,6 @@ internal fun adt(c: KSClassDeclaration, logger: KSPLogger): ADT = OpticsTarget.LENS -> evalAnnotatedDataClass(c, c.qualifiedNameOrSimpleName.lensErrorMessage, logger) .let(::LensTarget) - OpticsTarget.OPTIONAL -> - evalAnnotatedDataClass(c, c.qualifiedNameOrSimpleName.optionalErrorMessage, logger) - .let(::OptionalTarget) - OpticsTarget.ISO -> evalAnnotatedIsoElement(c, logger).let(::IsoTarget) OpticsTarget.PRISM -> evalAnnotatedPrismElement(c, logger).let(::PrismTarget) OpticsTarget.DSL -> evalAnnotatedDslElement(c, logger) } @@ -29,18 +25,11 @@ internal fun KSClassDeclaration.targets(): List = targetsFromOpticsAnnotation().let { targets -> when { isSealed -> - if (targets.isEmpty()) - listOf(OpticsTarget.PRISM, OpticsTarget.DSL) - else targets.filter { it == OpticsTarget.PRISM || it == OpticsTarget.DSL } + listOf(OpticsTarget.PRISM, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } else -> - if (targets.isEmpty()) - listOf(OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.OPTIONAL, OpticsTarget.DSL) - else targets.filter { - when (it) { - OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.OPTIONAL, OpticsTarget.DSL -> true - else -> false - } - } + listOf(OpticsTarget.LENS, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } } } @@ -48,13 +37,11 @@ internal fun KSClassDeclaration.targetsFromOpticsAnnotation(): List).orEmpty().mapNotNull { it as? KSType } } + ?.flatMap { arg -> (arg.value as? ArrayList<*>).orEmpty().mapNotNull { it as? KSType } } ?.mapNotNull { when (it.qualifiedString() ) { - "arrow.optics.OpticsTarget.ISO" -> OpticsTarget.ISO "arrow.optics.OpticsTarget.LENS" -> OpticsTarget.LENS "arrow.optics.OpticsTarget.PRISM" -> OpticsTarget.PRISM - "arrow.optics.OpticsTarget.OPTIONAL" -> OpticsTarget.OPTIONAL "arrow.optics.OpticsTarget.DSL" -> OpticsTarget.DSL else -> null } @@ -82,9 +69,6 @@ internal fun evalAnnotatedPrismElement( internal val KSDeclaration.qualifiedNameOrSimpleName: String get() = (qualifiedName ?: simpleName).asString() -internal fun KSClassDeclaration.sealedSubclassFqNameList(): List = - getSealedSubclasses().mapNotNull { it.qualifiedName?.asString() }.toList() - internal fun evalAnnotatedDataClass( element: KSClassDeclaration, errorMessage: String, @@ -113,23 +97,6 @@ internal fun evalAnnotatedDslElement(element: KSClassDeclaration, logger: KSPLog else -> throw IllegalStateException("should only be sealed or data by now") } -internal fun evalAnnotatedIsoElement(element: KSClassDeclaration, logger: KSPLogger): List = - when { - element.isData -> - element - .getConstructorTypesNames() - .zip(element.getConstructorParamNames(), Focus.Companion::invoke) - .takeIf { it.size <= 22 } - ?: run { - logger.error(element.qualifiedNameOrSimpleName.isoTooBigErrorMessage, element) - emptyList() - } - else -> { - logger.error(element.qualifiedNameOrSimpleName.isoErrorMessage, element) - emptyList() - } - } - internal fun KSClassDeclaration.getConstructorTypesNames(): List = primaryConstructor?.parameters?.map { it.type.resolve().qualifiedString() }.orEmpty() diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt index 6252cb46990..e765602b161 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/snippets.kt @@ -3,12 +3,10 @@ package arrow.optics.plugin.internals internal fun ADT.snippets(): List = targets.map { when (it) { - is IsoTarget -> generateIsos(this, it) is PrismTarget -> generatePrisms(this, it) is LensTarget -> generateLenses(this, it) - is OptionalTarget -> generateOptionals(this, it) is SealedClassDsl -> generatePrismDsl(this, it) - is DataClassDsl -> generateOptionalDsl(this, it) + generateLensDsl(this, it) + is DataClassDsl -> generateLensDsl(this, it) } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt index 66a03d2b07e..ed4e1dfa87c 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/DSLTests.kt @@ -10,7 +10,7 @@ class DSLTests { |$imports |$dslModel |$dslValues - |val modify = Employees.employees.every(Every.list()).company.address + |val modify = Employees.employees.every(Every.list()).company.notNull.address | .street.name.modify(employees, String::toUpperCase) |val r = modify.employees.map { it.company?.address?.street?.name }.toString() """.evals("r" to "[LAMBDA STREET, LAMBDA STREET]") diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt deleted file mode 100755 index 117ffcf7192..00000000000 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/IsoTests.kt +++ /dev/null @@ -1,97 +0,0 @@ -package arrow.optics.plugin - -import arrow.optics.plugin.internals.isoTooBigErrorMessage -import arrow.optics.plugin.internals.noCompanion -import org.junit.jupiter.api.Test - -class IsoTests { - - @Test - fun `Isos will be generated for data class`() { - """ - |$imports - |@optics - |data class IsoData( - | val field1: String - |) { companion object } - | - |val i: Iso = IsoData.iso - |val r = i != null - """.evals("r" to true) - } - - @Test - fun `Isos will be generated for generic data class`() { - """ - |$imports - |@optics - |data class IsoData( - | val field1: A - |) { companion object } - | - |val i: Iso, String> = IsoData.iso() - |val r = i != null - """.evals("r" to true) - } - - @Test - fun `Isos will be generated for data class with secondary constructors`() { - """ - |$imports - |@optics - |data class IsoSecondaryConstructor(val fieldNumber: Int, val fieldString: String) { - | constructor(number: Int) : this(number, number.toString()) - | companion object - |} - | - |val i: Iso> = IsoSecondaryConstructor.iso - |val r = i != null - """.evals("r" to true) - } - - @Test - fun `Iso generation requires companion object declaration`() { - """ - |$imports - |@optics - |data class IsoNoCompanion( - | val field1: String - |) - """.failsWith { it.contains("IsoNoCompanion".noCompanion) } - } - - @Test - fun `Isos cannot be generated for huge classes`() { - """ - |$imports - |@optics - |data class IsoXXL( - | val field1: String, - | val field2: String, - | val field3: String, - | val field4: String, - | val field5: String, - | val field6: String, - | val field7: String, - | val field8: String, - | val field9: String, - | val field10: String, - | val field11: String, - | val field12: String, - | val field13: String, - | val field14: String, - | val field15: String, - | val field16: String, - | val field17: String, - | val field18: String, - | val field19: String, - | val field20: String, - | val field21: String, - | val field22: String, - | val field23: String - |) { - | companion object - |} - """.failsWith { it.contains("IsoXXL".isoTooBigErrorMessage) } - } -} diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt index be661dfe02d..89d84a8c492 100755 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/OptionalTests.kt @@ -13,8 +13,9 @@ class OptionalTests { | val field1: String? |) { companion object } | - |val i: Optional = OptionalData.field1 - |val r = i != null + |val i: Lens = OptionalData.field1 + |val j: Optional = OptionalData.field1.notNull + |val r = i != null && j != null """.evals("r" to true) } @@ -27,8 +28,9 @@ class OptionalTests { | val field1: A? |) { companion object } | - |val i: Optional, String> = OptionalData.field1() - |val r = i != null + |val i: Lens, String?> = OptionalData.field1() + |val j: Optional, String> = OptionalData.field1().notNull + |val r = i != null && j != null """.evals("r" to true) } @@ -42,8 +44,9 @@ class OptionalTests { | companion object |} | - |val i: Optional = OptionalSecondaryConstructor.fieldString - |val r = i != null + |val i: Lens = OptionalSecondaryConstructor.fieldString + |val j: Optional = OptionalSecondaryConstructor.fieldString.notNull + |val r = i != null && j != null """.evals("r" to true) } } diff --git a/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt b/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt index e73e4c22fc7..bbe8606c584 100644 --- a/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt +++ b/arrow-libs/optics/arrow-optics-reflect/src/main/kotlin/arrow/optics/Reflection.kt @@ -23,10 +23,6 @@ public inline fun instance(): Prism = override fun reverseGet(focus: A): S = focus } -/** Focuses on a given field */ -public val ((S) -> A).ogetter: Getter - get() = Getter { s -> this(s) } - /** * [Lens] that focuses on a field in a data class * @@ -43,15 +39,13 @@ public val KProperty1.lens: Lens public val KProperty1.optional: Optional get() = lens compose Optional.nullable() -public val ((S) -> Iterable).iter: Fold - get() = ogetter compose Fold.iterable() - public val KProperty1>.every: Traversal get() = lens compose Every.list() public val KProperty1>.values: Traversal get() = lens compose Every.map() +@Suppress("UNCHECKED_CAST") private fun clone(prop: KProperty1, value: S, newField: A): S { // based on https://stackoverflow.com/questions/49511098/call-data-class-copy-via-reflection val klass = prop.instanceParameter?.type?.classifier as? KClass<*> diff --git a/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt b/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt index b4c32470df9..ebb6652f9b8 100644 --- a/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt +++ b/arrow-libs/optics/arrow-optics-reflect/src/test/kotlin/arrow/optics/ReflectionTest.kt @@ -3,7 +3,6 @@ package arrow.optics import arrow.core.test.UnitSpec import io.kotest.matchers.shouldBe import io.kotest.property.Arb -import io.kotest.property.arbitrary.int import io.kotest.property.arbitrary.string data class Person(val name: String, val friends: List) @@ -14,13 +13,6 @@ object Spoon: Cutlery object ReflectionTest: UnitSpec() { init { - "optional for function" { - checkAll(Arb.list(Arb.int())) { ints -> - val firsty = { it: List -> it.firstOrNull() } - firsty.ogetter.get(ints) shouldBe ints.firstOrNull() - } - } - "lenses for field, get" { checkAll(Arb.string(), Arb.list(Arb.string())) { nm, fs -> val p = Person(nm, fs.toMutableList()) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt index f8fd663cf69..48786989670 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Optional.kt @@ -205,10 +205,19 @@ public interface POptional : PTraversal { set = { list, newTail -> if (list.isNotEmpty()) list[0] prependTo newTail else emptyList() } ) + /** + * [Optional] to safely operate in a nullable value. + */ @JvmStatic public fun nullable(): Optional = Optional( getOption = { it.toOption() }, set = { source, new -> source?.let { new } } ) + + /** + * [Optional] to safely operate in a nullable value. + */ + @JvmStatic + public fun notNull(): Optional = nullable() } } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt index 5b6bbcdb7ed..64535741494 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/Prism.kt @@ -1,6 +1,8 @@ package arrow.optics import arrow.core.Either +import arrow.core.Either.Left +import arrow.core.Either.Right import arrow.core.None import arrow.core.Option import arrow.core.Some @@ -85,13 +87,13 @@ public interface PPrism : POptional { PPrism( { it.fold( - { a -> getOrModify(a).bimap({ Either.Left(it) }, { Either.Left(it) }) }, - { c -> Either.Right(Either.Right(c)) }) + { a -> getOrModify(a).bimap(::Left, ::Left) }, + { c -> Right(Right(c)) }) }, { when (it) { - is Either.Left -> Either.Left(reverseGet(it.value)) - is Either.Right -> Either.Right(it.value) + is Left -> Left(reverseGet(it.value)) + is Right -> Right(it.value) } } ) @@ -103,8 +105,8 @@ public interface PPrism : POptional { PPrism( { it.fold( - { c -> Either.Right(Either.Left(c)) }, - { s -> getOrModify(s).bimap({ Either.Right(it) }, { Either.Right(it) }) }) + { c -> Right(Left(c)) }, + { s -> getOrModify(s).bimap(::Right, ::Right) }) }, { it.map(this::reverseGet) } ) @@ -146,7 +148,7 @@ public interface PPrism : POptional { * A [PPrism] that checks for equality with a given value [a] */ public fun only(a: A, eq: (constant: A, other: A) -> Boolean = { aa, b -> aa == b }): Prism = Prism( - getOrModify = { a2 -> (if (eq(a, a2)) Either.Left(a) else Either.Right(Unit)) }, + getOrModify = { a2 -> (if (eq(a, a2)) Left(a) else Right(Unit)) }, reverseGet = { a } ) @@ -156,7 +158,7 @@ public interface PPrism : POptional { @JvmStatic public fun pSome(): PPrism, Option, A, B> = PPrism( - getOrModify = { option -> option.fold({ Either.Left(None) }, { Either.Right(it) }) }, + getOrModify = { option -> option.fold({ Left(None) }, ::Right) }, reverseGet = ::Some ) @@ -173,7 +175,7 @@ public interface PPrism : POptional { @JvmStatic public fun none(): Prism, Unit> = Prism( - getOrModify = { option -> option.fold({ Either.Right(Unit) }, { Either.Left(option) }) }, + getOrModify = { option -> option.fold({ Right(Unit) }, { Left(option) }) }, reverseGet = { _ -> None } ) } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt index 55b42bd4257..4ea746447b1 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/at.kt @@ -10,38 +10,28 @@ import arrow.optics.typeclasses.At * DSL to compose [At] with a [Lens] for a structure [S] to focus in on [A] at given index [I]. * * @receiver [Lens] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] + * @param at [At] instance to provide a [Lens] to zoom into [S] at [I] * @param i index [I] to zoom into [S] and find focus [A] * @return [Lens] with a focus in [A] at given index [I]. */ -public fun Lens.at(AT: At, i: I): Lens = this.compose(AT.at(i)) - -/** - * DSL to compose [At] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Prism] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ -public fun Prism.at(AT: At, i: I): Optional = this.compose(AT.at(i)) +public fun Lens.at(at: At, i: I): Lens = this.compose(at.at(i)) /** * DSL to compose [At] with an [Optional] for a structure [S] to focus in on [A] at given index [I]. * - * @receiver [Optional] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] + * @receiver [Optional] or [Prism] with a focus in [S] + * @param at [At] instance to provide a [Lens] to zoom into [S] at [I] * @param i index [I] to zoom into [S] and find focus [A] * @return [Optional] with a focus in [A] at given index [I]. */ -public fun Optional.at(AT: At, i: I): Optional = this.compose(AT.at(i)) +public fun Optional.at(at: At, i: I): Optional = this.compose(at.at(i)) /** * DSL to compose [At] with a [Traversal] for a structure [S] to focus in on [A] at given index [I]. * * @receiver [Traversal] with a focus in [S] - * @param AT [At] instance to provide a [Lens] to zoom into [S] at [I] + * @param at [At] instance to provide a [Lens] to zoom into [S] at [I] * @param i index [I] to zoom into [S] and find focus [A] * @return [Traversal] with a focus in [A] at given index [I]. */ -public fun Traversal.at(AT: At, i: I): Traversal = this.compose(AT.at(i)) +public fun Traversal.at(at: At, i: I): Traversal = this.compose(at.at(i)) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt index ce4f13f70cb..4cb645f8ed3 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/every.kt @@ -1,42 +1,12 @@ package arrow.optics.dsl -import arrow.optics.Lens -import arrow.optics.Optional -import arrow.optics.Prism import arrow.optics.Traversal -/** - * DSL to compose [Traversal] with a [Lens] for a structure [S] to see all its foci [A] - * - * @receiver [Lens] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] - * @return [Traversal] with a focus in [A] - */ -public fun Lens.every(TR: Traversal): Traversal = this.compose(TR) - -/** - * DSL to compose [Traversal] with a [Prism] for a structure [S] to see all its foci [A] - * - * @receiver [Prism] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] - * @return [Traversal] with a focus in [A] - */ -public fun Prism.every(TR: Traversal): Traversal = this.compose(TR) - -/** - * DSL to compose [Traversal] with an [Optional] for a structure [S] to see all its foci [A] - * - * @receiver [Optional] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] - * @return [Traversal] with a focus in [A] - */ -public fun Optional.every(TR: Traversal): Traversal = this.compose(TR) - /** * DSL to compose [Traversal] with a [Traversal] for a structure [S] to see all its foci [A] * * @receiver [Traversal] with a focus in [S] - * @param TR [Traversal] that can focus into a structure [S] to see all its foci [A] + * @param tr [Traversal] that can focus into a structure [S] to see all its foci [A] * @return [Traversal] with a focus in [A] */ -public fun Traversal.every(TR: Traversal): Traversal = this.compose(TR) +public fun Traversal.every(tr: Traversal): Traversal = this.compose(tr) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt index 241c9f34790..61f5b0a5385 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt @@ -10,38 +10,28 @@ import arrow.optics.typeclasses.Index * DSL to compose [Index] with a [Lens] for a structure [S] to focus in on [A] at given index [I] * * @receiver [Lens] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] + * @param idx [Index] instance to provide a [Optional] to focus into [S] at [I] * @param i index [I] to focus into [S] and find focus [A] * @return [Optional] with a focus in [A] at given index [I] */ -public fun Lens.index(ID: Index, i: I): Optional = this.compose(ID.index(i)) - -/** - * DSL to compose [Index] with a [Prism] for a structure [S] to focus in on [A] at given index [I] - * - * @receiver [Prism] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I] - */ -public fun Prism.index(ID: Index, i: I): Optional = this.compose(ID.index(i)) +public fun Lens.index(idx: Index, i: I): Optional = this.compose(idx.index(i)) /** * DSL to compose [Index] with an [Optional] for a structure [S] to focus in on [A] at given index [I] * - * @receiver [Optional] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] + * @receiver [Optional] or [Prism] with a focus in [S] + * @param idx [Index] instance to provide a [Optional] to focus into [S] at [I] * @param i index [I] to focus into [S] and find focus [A] * @return [Optional] with a focus in [A] at given index [I] */ -public fun Optional.index(ID: Index, i: I): Optional = this.compose(ID.index(i)) +public fun Optional.index(idx: Index, i: I): Optional = this.compose(idx.index(i)) /** * DSL to compose [Index] with a [Traversal] for a structure [S] to focus in on [A] at given index [I] * * @receiver [Traversal] with a focus in [S] - * @param ID [Index] instance to provide a [Optional] to focus into [S] at [I] + * @param idx [Index] instance to provide a [Optional] to focus into [S] at [I] * @param i index [I] to focus into [S] and find focus [A] * @return [Traversal] with a focus in [A] at given index [I]. */ -public fun Traversal.index(ID: Index, i: I): Traversal = this.compose(ID.index(i)) +public fun Traversal.index(idx: Index, i: I): Traversal = this.compose(idx.index(i)) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/nullable.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/nullable.kt new file mode 100644 index 00000000000..af5d3c1df6b --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/nullable.kt @@ -0,0 +1,23 @@ +package arrow.optics.dsl + +import arrow.optics.Lens +import arrow.optics.Optional +import arrow.optics.POptional +import arrow.optics.Prism +import arrow.optics.Traversal + +/** + * DSL to compose an [Optional] with focus on a nullable type with [notNull]. + * + * @receiver [Optional], [Lens], or [Prism] with a focus in <[S]?> + * @return [Optional] with a focus in [S] + */ +public inline val Optional.notNull: Optional inline get() = this.compose(POptional.notNull()) + +/** + * DSL to compose a [Traversal] with focus on a nullable type with [notNull]. + * + * @receiver [Traversal] with a focus in <[S]?> + * @return [Traversal] with a focus in [S] + */ +public inline val Traversal.notNull: Traversal inline get() = this.compose(POptional.notNull()) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt index a6ec24ab31b..18239669eae 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/option.kt @@ -6,27 +6,10 @@ import arrow.optics.Optional import arrow.optics.Prism import arrow.optics.Traversal -/** - * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Lens] with a focus of [Option]<[S]> - * - * @receiver [Lens] with a focus in [Option]<[S]> - * @return [Optional] with a focus in [S] - */ -public inline val Lens>.some: Optional inline get() = this.compose(Prism.some()) - - -/** - * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Prism] with a focus of [Option]<[S]> - * - * @receiver [Prism] with a focus in [Option]<[S]> - * @return [Prism] with a focus in [S] - */ -public inline val Prism>.some: Prism inline get() = this.compose(Prism.some()) - /** * DSL to compose a [Prism] with focus [arrow.core.Some] with a [Optional] with a focus of [Option]<[S]> * - * @receiver [Optional] with a focus in [Option]<[S]> + * @receiver [Optional], [Lens], or [Prism] with a focus in [Option]<[S]> * @return [Optional] with a focus in [S] */ public inline val Optional>.some: Optional inline get() = this.compose(Prism.some()) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt index bde68db7922..b9305affdcd 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/predef.kt @@ -4,7 +4,7 @@ import arrow.typeclasses.Monoid @Suppress("ClassName") internal object EMPTY_VALUE { - @Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE") + @Suppress("UNCHECKED_CAST") inline fun unbox(value: Any?): T = if (value === this) null as T else value as T } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt index 41fd39e9139..07258def13c 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt @@ -5,7 +5,6 @@ import arrow.core.Option import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.PLens -import arrow.optics.Prism import arrow.optics.Traversal import kotlin.jvm.JvmStatic @@ -36,15 +35,6 @@ public fun interface At { public fun Lens.at(i: I): Lens = this@at.compose(this@At.at(i)) - /** - * DSL to compose [At] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Prism] with a focus in [S] - * @param i index [I] to zoom into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public fun Prism.at(i: I): Optional = this.compose(this@At.at(i)) - /** * DSL to compose [At] with an [Optional] for a structure [S] to focus in on [A] at given index [I]. * diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt index 63b2325b354..a8c4a2bb22f 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/Index.kt @@ -4,11 +4,9 @@ import arrow.core.NonEmptyList import arrow.core.left import arrow.core.right import arrow.core.toNonEmptyListOrNull -import arrow.optics.Lens import arrow.optics.Optional import arrow.optics.PLens import arrow.optics.POptional -import arrow.optics.Prism import arrow.optics.Traversal import kotlin.jvm.JvmStatic @@ -29,24 +27,6 @@ public fun interface Index { */ public fun index(i: I): Optional - /** - * DSL to compose [Index] with a [Lens] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Lens] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public fun Lens.index(i: I): Optional = this.compose(this@Index.index(i)) - - /** - * DSL to compose [Index] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Prism] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public fun Prism.index(i: I): Optional = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with an [Optional] for a structure [S] to focus in on [A] at given index [I]. * @@ -65,24 +45,6 @@ public fun interface Index { */ public fun Traversal.index(i: I): Traversal = this.compose(this@Index.index(i)) - /** - * DSL to compose [Index] with a [Lens] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Lens] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public operator fun Lens.get(i: I): Optional = this.compose(this@Index.index(i)) - - /** - * DSL to compose [Index] with a [Prism] for a structure [S] to focus in on [A] at given index [I]. - * - * @receiver [Prism] with a focus in [S] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I]. - */ - public operator fun Prism.get(i: I): Optional = this.compose(this@Index.index(i)) - /** * DSL to compose [Index] with an [Optional] for a structure [S] to focus in on [A] at given index [I]. * @@ -159,7 +121,7 @@ public fun interface Index { @JvmStatic public fun string(): Index = Index { i -> - PLens.stringToList() compose Index.list().index(i) + PLens.stringToList() compose list().index(i) } } } diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt deleted file mode 100644 index f9d299003a7..00000000000 --- a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt +++ /dev/null @@ -1,23 +0,0 @@ -// This file was automatically generated from Optional.kt by Knit tool. Do not edit. -package arrow.optics.examples.exampleOptional01 - -import arrow.core.None -import arrow.core.Option -import arrow.core.Some -import arrow.optics.Optional - -data class User(val username: String, val email: Option) { - companion object { - // can be out generated by @optics - val email: Optional = Optional(User::email) { user, email -> - user.copy(email = Some(email)) - } - } -} - -fun main(args: Array) { - val original = User("arrow-user", None) - val set = User.email.set(original, "arRoW-UsEr@arrow-Kt.IO") - val modified = User.email.modify(set, String::toLowerCase) - println("original: $original, set: $set, modified: $modified") -} From 03b488bc4a87b7df2bae79d1ffd6e467078e6c44 Mon Sep 17 00:00:00 2001 From: serras Date: Thu, 15 Dec 2022 12:21:03 +0000 Subject: [PATCH 08/11] Update API files --- .../api/arrow-optics-reflect.api | 2 - .../optics/arrow-optics/api/arrow-optics.api | 477 ++---------------- 2 files changed, 32 insertions(+), 447 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api b/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api index 4a3b3c3ea11..440ead51bc1 100644 --- a/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api +++ b/arrow-libs/optics/arrow-optics-reflect/api/arrow-optics-reflect.api @@ -1,8 +1,6 @@ public final class arrow/optics/ReflectionKt { public static final fun getEvery (Lkotlin/reflect/KProperty1;)Larrow/optics/PTraversal; - public static final fun getIter (Lkotlin/jvm/functions/Function1;)Larrow/optics/Fold; public static final fun getLens (Lkotlin/reflect/KProperty1;)Larrow/optics/PLens; - public static final fun getOgetter (Lkotlin/jvm/functions/Function1;)Larrow/optics/PGetter; public static final fun getOptional (Lkotlin/reflect/KProperty1;)Larrow/optics/POptional; public static final fun getValues (Lkotlin/reflect/KProperty1;)Larrow/optics/PTraversal; public static final fun instance (Lkotlin/reflect/KClass;)Larrow/optics/PPrism; diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index 1eeeb7653f7..b57071ebd62 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -1,7 +1,7 @@ public abstract interface class arrow/optics/Copy { public abstract fun inside (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)V - public abstract fun set (Larrow/optics/PSetter;Ljava/lang/Object;)V - public abstract fun transform (Larrow/optics/PSetter;Lkotlin/jvm/functions/Function1;)V + public abstract fun set (Larrow/optics/PTraversal;Ljava/lang/Object;)V + public abstract fun transform (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)V } public final class arrow/optics/Copy$DefaultImpls { @@ -32,89 +32,6 @@ public final class arrow/optics/Every { public static final fun tuple9 ()Larrow/optics/PTraversal; } -public abstract interface class arrow/optics/Fold { - public static final field Companion Larrow/optics/Fold$Companion; - public abstract fun all (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public abstract fun any (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public abstract fun choice (Larrow/optics/Fold;)Larrow/optics/Fold; - public abstract fun combineAll (Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun compose (Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun either ()Larrow/optics/Fold; - public abstract fun exists (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public abstract fun findOrNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun firstOrNull (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun fold (Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getAll (Ljava/lang/Object;)Ljava/util/List; - public abstract fun isEmpty (Ljava/lang/Object;)Z - public abstract fun isNotEmpty (Ljava/lang/Object;)Z - public static fun iterable ()Larrow/optics/Fold; - public abstract fun lastOrNull (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun left ()Larrow/optics/Fold; - public static fun list ()Larrow/optics/Fold; - public static fun map ()Larrow/optics/Fold; - public static fun nonEmptyList ()Larrow/optics/Fold; - public static fun option ()Larrow/optics/Fold; - public static fun pair ()Larrow/optics/Fold; - public abstract fun plus (Larrow/optics/Fold;)Larrow/optics/Fold; - public abstract fun right ()Larrow/optics/Fold; - public static fun sequence ()Larrow/optics/Fold; - public abstract fun size (Ljava/lang/Object;)I - public static fun string ()Larrow/optics/Fold; - public static fun triple ()Larrow/optics/Fold; - public static fun tuple10 ()Larrow/optics/Fold; - public static fun tuple4 ()Larrow/optics/Fold; - public static fun tuple5 ()Larrow/optics/Fold; - public static fun tuple6 ()Larrow/optics/Fold; - public static fun tuple7 ()Larrow/optics/Fold; - public static fun tuple8 ()Larrow/optics/Fold; - public static fun tuple9 ()Larrow/optics/Fold; -} - -public final class arrow/optics/Fold$Companion { - public final fun codiagonal ()Larrow/optics/Fold; - public final fun either ()Larrow/optics/Fold; - public final fun id ()Larrow/optics/Fold; - public final fun iterable ()Larrow/optics/Fold; - public final fun list ()Larrow/optics/Fold; - public final fun map ()Larrow/optics/Fold; - public final fun nonEmptyList ()Larrow/optics/Fold; - public final fun option ()Larrow/optics/Fold; - public final fun pair ()Larrow/optics/Fold; - public final fun select (Lkotlin/jvm/functions/Function1;)Larrow/optics/Fold; - public final fun sequence ()Larrow/optics/Fold; - public final fun string ()Larrow/optics/Fold; - public final fun triple ()Larrow/optics/Fold; - public final fun tuple10 ()Larrow/optics/Fold; - public final fun tuple4 ()Larrow/optics/Fold; - public final fun tuple5 ()Larrow/optics/Fold; - public final fun tuple6 ()Larrow/optics/Fold; - public final fun tuple7 ()Larrow/optics/Fold; - public final fun tuple8 ()Larrow/optics/Fold; - public final fun tuple9 ()Larrow/optics/Fold; - public final fun void ()Larrow/optics/Fold; -} - -public final class arrow/optics/Fold$DefaultImpls { - public static fun all (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/Fold;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun combineAll (Larrow/optics/Fold;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/Fold;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun exists (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun firstOrNull (Larrow/optics/Fold;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/Fold;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/Fold;Ljava/lang/Object;)Ljava/util/List; - public static fun isEmpty (Larrow/optics/Fold;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/Fold;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/Fold;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/Fold;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun right (Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun size (Larrow/optics/Fold;Ljava/lang/Object;)I -} - public final class arrow/optics/ListKt { public static final fun cons (Ljava/lang/Object;Ljava/util/List;)Ljava/util/List; public static final fun get (Larrow/optics/PLens;I)Larrow/optics/POptional; @@ -126,178 +43,11 @@ public final class arrow/optics/ListKt { public abstract interface annotation class arrow/optics/OpticsCopyMarker : java/lang/annotation/Annotation { } -public final class arrow/optics/OptionalGetterKt { - public static final fun OptionalGetter (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; -} - public final class arrow/optics/OptionalKt { public static final fun Optional (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; } -public abstract interface class arrow/optics/PGetter : arrow/optics/POptionalGetter { - public static final field Companion Larrow/optics/PGetter$Companion; - public abstract fun choice (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public abstract fun compose (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public abstract fun first ()Larrow/optics/PGetter; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; - public abstract fun left ()Larrow/optics/PGetter; - public abstract fun plus (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public abstract fun right ()Larrow/optics/PGetter; - public abstract fun second ()Larrow/optics/PGetter; - public abstract fun split (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public abstract fun zip (Larrow/optics/PGetter;)Larrow/optics/PGetter; -} - -public final class arrow/optics/PGetter$Companion { - public final fun codiagonal ()Larrow/optics/PGetter; - public final fun id ()Larrow/optics/PGetter; -} - -public final class arrow/optics/PGetter$DefaultImpls { - public static fun all (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun choice (Larrow/optics/PGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun combineAll (Larrow/optics/PGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun compose (Larrow/optics/PGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun exists (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/PGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun firstOrNull (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/util/List; - public static fun getOrModify (Larrow/optics/PGetter;Ljava/lang/Object;)Larrow/core/Either; - public static fun getOrNull (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun isEmpty (Larrow/optics/PGetter;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/PGetter;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/PGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun plus (Larrow/optics/PGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun plus (Larrow/optics/PGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun right (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun second (Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun size (Larrow/optics/PGetter;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun zip (Larrow/optics/PGetter;Larrow/optics/PGetter;)Larrow/optics/PGetter; -} - -public abstract interface class arrow/optics/PIso : arrow/optics/PLens, arrow/optics/PPrism { - public static final field Companion Larrow/optics/PIso$Companion; - public abstract fun compose (Larrow/optics/PIso;)Larrow/optics/PIso; - public abstract fun first ()Larrow/optics/PIso; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun get (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; - public abstract fun left ()Larrow/optics/PIso; - public static fun listToOptionNel ()Larrow/optics/PIso; - public static fun listToPOptionNel ()Larrow/optics/PIso; - public static fun mapToSet ()Larrow/optics/PIso; - public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun nullableToOption ()Larrow/optics/PIso; - public static fun nullableToPOption ()Larrow/optics/PIso; - public static fun optionToEither ()Larrow/optics/PIso; - public static fun optionToNullable ()Larrow/optics/PIso; - public static fun optionToPEither ()Larrow/optics/PIso; - public static fun optionToPNullable ()Larrow/optics/PIso; - public abstract fun plus (Larrow/optics/PIso;)Larrow/optics/PIso; - public abstract fun reverse ()Larrow/optics/PIso; - public abstract fun reverseGet (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun right ()Larrow/optics/PIso; - public abstract fun second ()Larrow/optics/PIso; - public abstract fun set (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun split (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun stringToList ()Larrow/optics/PIso; -} - -public final class arrow/optics/PIso$Companion { - public final fun id ()Larrow/optics/PIso; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PIso; - public final fun listToOptionNel ()Larrow/optics/PIso; - public final fun listToPOptionNel ()Larrow/optics/PIso; - public final fun mapToSet ()Larrow/optics/PIso; - public final fun nullableToOption ()Larrow/optics/PIso; - public final fun nullableToPOption ()Larrow/optics/PIso; - public final fun optionToEither ()Larrow/optics/PIso; - public final fun optionToNullable ()Larrow/optics/PIso; - public final fun optionToPEither ()Larrow/optics/PIso; - public final fun optionToPNullable ()Larrow/optics/PIso; - public final fun stringToList ()Larrow/optics/PIso; -} - -public final class arrow/optics/PIso$DefaultImpls { - public static fun all (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun choice (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun choice (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun combineAll (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun compose (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun compose (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun exists (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun firstOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/PIso;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun getEvery (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun getOrModify (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/core/Either; - public static fun getOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun isEmpty (Larrow/optics/PIso;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/PIso;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun lift (Larrow/optics/PIso;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun liftNullable (Larrow/optics/PIso;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun modify (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun modifyNullable (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/PIso;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun plus (Larrow/optics/PIso;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/PIso;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun plus (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun reverse (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun right (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun second (Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun set (Larrow/optics/PIso;Ljava/lang/Object;)Ljava/lang/Object; - public static fun set (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun setNullable (Larrow/optics/PIso;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; - public static fun size (Larrow/optics/PIso;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; - public static fun split (Larrow/optics/PIso;Larrow/optics/PIso;)Larrow/optics/PIso; - public static fun split (Larrow/optics/PIso;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun zip (Larrow/optics/PIso;Larrow/optics/PGetter;)Larrow/optics/PGetter; -} - -public abstract interface class arrow/optics/PLens : arrow/optics/PGetter, arrow/optics/POptional { +public abstract interface class arrow/optics/PLens : arrow/optics/POptional { public static final field Companion Larrow/optics/PLens$Companion; public abstract fun choice (Larrow/optics/PLens;)Larrow/optics/PLens; public abstract fun compose (Larrow/optics/PLens;)Larrow/optics/PLens; @@ -315,6 +65,7 @@ public abstract interface class arrow/optics/PLens : arrow/optics/PGetter, arrow public abstract fun second ()Larrow/optics/PLens; public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun split (Larrow/optics/PLens;)Larrow/optics/PLens; + public static fun stringToList ()Larrow/optics/PLens; public static fun tripleFirst ()Larrow/optics/PLens; public static fun triplePFirst ()Larrow/optics/PLens; public static fun triplePSecond ()Larrow/optics/PLens; @@ -325,7 +76,7 @@ public abstract interface class arrow/optics/PLens : arrow/optics/PGetter, arrow public final class arrow/optics/PLens$Companion { public final fun codiagonal ()Larrow/optics/PLens; - public final fun id ()Larrow/optics/PIso; + public final fun id ()Larrow/optics/PLens; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/PLens; public final fun nonEmptyListHead ()Larrow/optics/PLens; public final fun nonEmptyListTail ()Larrow/optics/PLens; @@ -333,6 +84,7 @@ public final class arrow/optics/PLens$Companion { public final fun pairPFirst ()Larrow/optics/PLens; public final fun pairPSecond ()Larrow/optics/PLens; public final fun pairSecond ()Larrow/optics/PLens; + public final fun stringToList ()Larrow/optics/PLens; public final fun tripleFirst ()Larrow/optics/PLens; public final fun triplePFirst ()Larrow/optics/PLens; public final fun triplePSecond ()Larrow/optics/PLens; @@ -344,20 +96,12 @@ public final class arrow/optics/PLens$Companion { public final class arrow/optics/PLens$DefaultImpls { public static fun all (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun choice (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun choice (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun compose (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun compose (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun compose (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -366,48 +110,40 @@ public final class arrow/optics/PLens$DefaultImpls { public static fun fold (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PIso;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrModify (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/core/Either; public static fun getOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object; public static fun isEmpty (Larrow/optics/PLens;Ljava/lang/Object;)Z public static fun isNotEmpty (Larrow/optics/PLens;Ljava/lang/Object;)Z public static fun lastOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PLens;)Larrow/optics/PGetter; public static fun lift (Larrow/optics/PLens;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/PLens;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun plus (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; public static fun plus (Larrow/optics/PLens;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/PLens;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun plus (Larrow/optics/PLens;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/PLens;)Larrow/optics/PGetter; public static fun second (Larrow/optics/PLens;)Larrow/optics/PLens; public static fun setNullable (Larrow/optics/PLens;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/PLens;Ljava/lang/Object;)I - public static fun split (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; public static fun split (Larrow/optics/PLens;Larrow/optics/PLens;)Larrow/optics/PLens; - public static fun zip (Larrow/optics/PLens;Larrow/optics/PGetter;)Larrow/optics/PGetter; } -public abstract interface class arrow/optics/POptional : arrow/optics/POptionalGetter, arrow/optics/PTraversal { +public abstract interface class arrow/optics/POptional : arrow/optics/PTraversal { public static final field Companion Larrow/optics/POptional$Companion; public abstract fun choice (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun compose (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun first ()Larrow/optics/POptional; public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; + public abstract fun getOrNull (Ljava/lang/Object;)Ljava/lang/Object; public static fun listHead ()Larrow/optics/POptional; public static fun listTail ()Larrow/optics/POptional; public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public abstract fun modifyNullable (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static fun notNull ()Larrow/optics/POptional; public static fun nullable ()Larrow/optics/POptional; public abstract fun plus (Larrow/optics/POptional;)Larrow/optics/POptional; public abstract fun second ()Larrow/optics/POptional; @@ -417,10 +153,11 @@ public abstract interface class arrow/optics/POptional : arrow/optics/POptionalG public final class arrow/optics/POptional$Companion { public final fun codiagonal ()Larrow/optics/POptional; - public final fun id ()Larrow/optics/PIso; + public final fun id ()Larrow/optics/POptional; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Larrow/optics/POptional; public final fun listHead ()Larrow/optics/POptional; public final fun listTail ()Larrow/optics/POptional; + public final fun notNull ()Larrow/optics/POptional; public final fun nullable ()Larrow/optics/POptional; public final fun void ()Larrow/optics/POptional; } @@ -428,16 +165,10 @@ public final class arrow/optics/POptional$Companion { public final class arrow/optics/POptional$DefaultImpls { public static fun all (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun choice (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun compose (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun compose (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -446,77 +177,24 @@ public final class arrow/optics/POptional$DefaultImpls { public static fun fold (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PIso;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PLens;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object; public static fun isEmpty (Larrow/optics/POptional;Ljava/lang/Object;)Z public static fun isNotEmpty (Larrow/optics/POptional;Ljava/lang/Object;)Z public static fun lastOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/POptional;)Larrow/optics/Fold; public static fun lift (Larrow/optics/POptional;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/POptional;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun plus (Larrow/optics/POptional;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/POptional;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun plus (Larrow/optics/POptional;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/POptional;)Larrow/optics/Fold; public static fun second (Larrow/optics/POptional;)Larrow/optics/POptional; public static fun setNullable (Larrow/optics/POptional;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/POptional;Ljava/lang/Object;)I } -public abstract interface class arrow/optics/POptionalGetter : arrow/optics/Fold { - public static final field Companion Larrow/optics/POptionalGetter$Companion; - public abstract fun choice (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public abstract fun compose (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; - public abstract fun first ()Larrow/optics/POptionalGetter; - public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either; - public abstract fun getOrNull (Ljava/lang/Object;)Ljava/lang/Object; - public abstract fun plus (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public abstract fun second ()Larrow/optics/POptionalGetter; -} - -public final class arrow/optics/POptionalGetter$Companion { - public final fun filter (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; - public final fun id ()Larrow/optics/PIso; - public final fun invoke (Lkotlin/jvm/functions/Function1;)Larrow/optics/POptionalGetter; -} - -public final class arrow/optics/POptionalGetter$DefaultImpls { - public static fun all (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun any (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/POptionalGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/POptionalGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun combineAll (Larrow/optics/POptionalGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/POptionalGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/POptionalGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun exists (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun findOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun first (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun firstOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun fold (Larrow/optics/POptionalGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun foldMap (Larrow/optics/POptionalGetter;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun getAll (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/util/List; - public static fun getOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun isEmpty (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Z - public static fun isNotEmpty (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Z - public static fun lastOrNull (Larrow/optics/POptionalGetter;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/POptionalGetter;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/POptionalGetter;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/POptionalGetter;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun right (Larrow/optics/POptionalGetter;)Larrow/optics/Fold; - public static fun second (Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun size (Larrow/optics/POptionalGetter;Ljava/lang/Object;)I -} - public abstract interface class arrow/optics/PPrism : arrow/optics/POptional { public static final field Companion Larrow/optics/PPrism$Companion; public abstract fun compose (Larrow/optics/PPrism;)Larrow/optics/PPrism; @@ -537,7 +215,7 @@ public abstract interface class arrow/optics/PPrism : arrow/optics/POptional { } public final class arrow/optics/PPrism$Companion { - public final fun id ()Larrow/optics/PIso; + public final fun id ()Larrow/optics/PPrism; public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Larrow/optics/PPrism; public final fun none ()Larrow/optics/PPrism; public final fun only (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Larrow/optics/PPrism; @@ -549,17 +227,11 @@ public final class arrow/optics/PPrism$Companion { public final class arrow/optics/PPrism$DefaultImpls { public static fun all (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun choice (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun choice (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; - public static fun choice (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun compose (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun compose (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -568,11 +240,9 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun fold (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun foldMap (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PIso;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PLens;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun getOrNull (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/lang/Object; public static fun isEmpty (Larrow/optics/PPrism;Ljava/lang/Object;)Z @@ -583,11 +253,8 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun liftNullable (Larrow/optics/PPrism;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun modify (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun modifyNullable (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/Fold;)Larrow/optics/Fold; public static fun plus (Larrow/optics/PPrism;Larrow/optics/POptional;)Larrow/optics/POptional; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/POptionalGetter;)Larrow/optics/POptionalGetter; public static fun plus (Larrow/optics/PPrism;Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static fun plus (Larrow/optics/PPrism;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun right (Larrow/optics/PPrism;)Larrow/optics/PPrism; public static fun second (Larrow/optics/PPrism;)Larrow/optics/PPrism; @@ -596,50 +263,28 @@ public final class arrow/optics/PPrism$DefaultImpls { public static fun size (Larrow/optics/PPrism;Ljava/lang/Object;)I } -public abstract interface class arrow/optics/PSetter { - public static final field Companion Larrow/optics/PSetter$Companion; - public abstract fun choice (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun compose (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun plus (Larrow/optics/PSetter;)Larrow/optics/PSetter; - public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public final class arrow/optics/PSetter$Companion { - public final fun codiagonal ()Larrow/optics/PSetter; - public final fun id ()Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function10;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function11;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function9;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function8;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function7;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function6;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function5;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function4;)Larrow/optics/PSetter; - public final fun invoke (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;)Larrow/optics/PSetter; -} - -public final class arrow/optics/PSetter$DefaultImpls { - public static fun choice (Larrow/optics/PSetter;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun compose (Larrow/optics/PSetter;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun lift (Larrow/optics/PSetter;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun plus (Larrow/optics/PSetter;Larrow/optics/PSetter;)Larrow/optics/PSetter; - public static fun set (Larrow/optics/PSetter;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; -} - -public abstract interface class arrow/optics/PTraversal : arrow/optics/Fold, arrow/optics/PSetter { +public abstract interface class arrow/optics/PTraversal { public static final field Companion Larrow/optics/PTraversal$Companion; + public abstract fun all (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public abstract fun any (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public abstract fun choice (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public abstract fun combineAll (Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun compose (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun either ()Larrow/optics/PTraversal; + public abstract fun exists (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z + public abstract fun findOrNull (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public abstract fun firstOrNull (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun fold (Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public abstract fun foldMap (Larrow/typeclasses/Monoid;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; - public abstract fun getEvery (Larrow/optics/PIso;)Larrow/optics/PTraversal; + public abstract fun getAll (Ljava/lang/Object;)Ljava/util/List; public abstract fun getEvery (Larrow/optics/PLens;)Larrow/optics/PTraversal; public abstract fun getEvery (Larrow/optics/POptional;)Larrow/optics/PTraversal; public abstract fun getEvery (Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public abstract fun getEvery (Larrow/optics/PSetter;)Larrow/optics/PSetter; public abstract fun getEvery (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; + public abstract fun isEmpty (Ljava/lang/Object;)Z + public abstract fun isNotEmpty (Ljava/lang/Object;)Z + public abstract fun lastOrNull (Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun lift (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static fun list ()Larrow/optics/PTraversal; public static fun map ()Larrow/optics/PTraversal; public abstract fun modify (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -657,6 +302,8 @@ public abstract interface class arrow/optics/PTraversal : arrow/optics/Fold, arr public static fun pair ()Larrow/optics/PTraversal; public abstract fun plus (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun sequence ()Larrow/optics/PTraversal; + public abstract fun set (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; + public abstract fun size (Ljava/lang/Object;)I public static fun string ()Larrow/optics/PTraversal; public static fun triple ()Larrow/optics/PTraversal; public static fun tuple10 ()Larrow/optics/PTraversal; @@ -711,33 +358,23 @@ public final class arrow/optics/PTraversal$Companion { public final class arrow/optics/PTraversal$DefaultImpls { public static fun all (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun any (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z - public static fun choice (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun choice (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun combineAll (Larrow/optics/PTraversal;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; - public static fun compose (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun compose (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun exists (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static fun findOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static fun firstOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object; public static fun fold (Larrow/optics/PTraversal;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object; public static fun getAll (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/util/List; - public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PIso;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PLens;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/POptional;)Larrow/optics/PTraversal; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PPrism;)Larrow/optics/PTraversal; - public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun getEvery (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; public static fun isEmpty (Larrow/optics/PTraversal;Ljava/lang/Object;)Z public static fun isNotEmpty (Larrow/optics/PTraversal;Ljava/lang/Object;)Z public static fun lastOrNull (Larrow/optics/PTraversal;Ljava/lang/Object;)Ljava/lang/Object; - public static fun left (Larrow/optics/PTraversal;)Larrow/optics/Fold; public static fun lift (Larrow/optics/PTraversal;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; - public static fun plus (Larrow/optics/PTraversal;Larrow/optics/Fold;)Larrow/optics/Fold; - public static fun plus (Larrow/optics/PTraversal;Larrow/optics/PSetter;)Larrow/optics/PSetter; public static fun plus (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static fun right (Larrow/optics/PTraversal;)Larrow/optics/Fold; public static fun set (Larrow/optics/PTraversal;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; public static fun size (Larrow/optics/PTraversal;Ljava/lang/Object;)I } @@ -747,55 +384,35 @@ public final class arrow/optics/PrismKt { } public final class arrow/optics/dsl/AtKt { - public static final fun at (Larrow/optics/Fold;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/Fold; - public static final fun at (Larrow/optics/PGetter;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PGetter; - public static final fun at (Larrow/optics/PIso;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PLens; public static final fun at (Larrow/optics/PLens;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PLens; public static final fun at (Larrow/optics/POptional;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun at (Larrow/optics/PPrism;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun at (Larrow/optics/PSetter;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PSetter; public static final fun at (Larrow/optics/PTraversal;Larrow/optics/typeclasses/At;Ljava/lang/Object;)Larrow/optics/PTraversal; } public final class arrow/optics/dsl/EveryKt { - public static final fun every (Larrow/optics/Fold;Larrow/optics/PTraversal;)Larrow/optics/Fold; - public static final fun every (Larrow/optics/PIso;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static final fun every (Larrow/optics/PLens;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static final fun every (Larrow/optics/POptional;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static final fun every (Larrow/optics/PPrism;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; - public static final fun every (Larrow/optics/PSetter;Larrow/optics/PTraversal;)Larrow/optics/PSetter; public static final fun every (Larrow/optics/PTraversal;Larrow/optics/PTraversal;)Larrow/optics/PTraversal; } public final class arrow/optics/dsl/IndexKt { - public static final fun index (Larrow/optics/Fold;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/Fold; - public static final fun index (Larrow/optics/PIso;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; public static final fun index (Larrow/optics/PLens;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; public static final fun index (Larrow/optics/POptional;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun index (Larrow/optics/PPrism;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; - public static final fun index (Larrow/optics/PSetter;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/PSetter; public static final fun index (Larrow/optics/PTraversal;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/PTraversal; } +public final class arrow/optics/dsl/NullableKt { + public static final fun getNotNull (Larrow/optics/POptional;)Larrow/optics/POptional; + public static final fun getNotNull (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; +} + public final class arrow/optics/dsl/OptionKt { - public static final fun getSome (Larrow/optics/Fold;)Larrow/optics/Fold; - public static final fun getSome (Larrow/optics/PIso;)Larrow/optics/PPrism; - public static final fun getSome (Larrow/optics/PLens;)Larrow/optics/POptional; public static final fun getSome (Larrow/optics/POptional;)Larrow/optics/POptional; - public static final fun getSome (Larrow/optics/PPrism;)Larrow/optics/PPrism; - public static final fun getSome (Larrow/optics/PSetter;)Larrow/optics/PSetter; public static final fun getSome (Larrow/optics/PTraversal;)Larrow/optics/PTraversal; } public abstract interface class arrow/optics/typeclasses/At { public static final field Companion Larrow/optics/typeclasses/At$Companion; - public abstract fun at (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun at (Larrow/optics/PGetter;Ljava/lang/Object;)Larrow/optics/PGetter; - public abstract fun at (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/PLens; public abstract fun at (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens; public abstract fun at (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun at (Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun at (Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public abstract fun at (Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; public abstract fun at (Ljava/lang/Object;)Larrow/optics/PLens; public static fun map ()Larrow/optics/typeclasses/At; @@ -803,19 +420,13 @@ public abstract interface class arrow/optics/typeclasses/At { } public final class arrow/optics/typeclasses/At$Companion { - public final fun fromIso (Larrow/optics/typeclasses/At;Larrow/optics/PIso;)Larrow/optics/typeclasses/At; public final fun map ()Larrow/optics/typeclasses/At; public final fun set ()Larrow/optics/typeclasses/At; } public final class arrow/optics/typeclasses/At$DefaultImpls { - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PGetter;Ljava/lang/Object;)Larrow/optics/PGetter; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/PLens; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/PLens; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public static fun at (Larrow/optics/typeclasses/At;Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; } @@ -836,7 +447,6 @@ public abstract interface class arrow/optics/typeclasses/Cons { } public final class arrow/optics/typeclasses/Cons$Companion { - public final fun fromIso (Larrow/optics/typeclasses/Cons;Larrow/optics/PIso;)Larrow/optics/typeclasses/Cons; public final fun invoke (Larrow/optics/PPrism;)Larrow/optics/typeclasses/Cons; public final fun list ()Larrow/optics/typeclasses/Cons; public final fun string ()Larrow/optics/typeclasses/Cons; @@ -860,7 +470,6 @@ public abstract interface class arrow/optics/typeclasses/FilterIndex { } public final class arrow/optics/typeclasses/FilterIndex$Companion { - public final fun fromIso (Larrow/optics/typeclasses/FilterIndex;Larrow/optics/PIso;)Larrow/optics/typeclasses/FilterIndex; public final fun list ()Larrow/optics/typeclasses/FilterIndex; public final fun map ()Larrow/optics/typeclasses/FilterIndex; public final fun nonEmptyList ()Larrow/optics/typeclasses/FilterIndex; @@ -870,19 +479,9 @@ public final class arrow/optics/typeclasses/FilterIndex$Companion { public abstract interface class arrow/optics/typeclasses/Index { public static final field Companion Larrow/optics/typeclasses/Index$Companion; - public abstract fun get (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun get (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun get (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public abstract fun get (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun get (Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun get (Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public abstract fun get (Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; - public abstract fun index (Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public abstract fun index (Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun index (Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public abstract fun index (Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun index (Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public abstract fun index (Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public abstract fun index (Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; public abstract fun index (Ljava/lang/Object;)Larrow/optics/POptional; public static fun list ()Larrow/optics/typeclasses/Index; @@ -893,7 +492,6 @@ public abstract interface class arrow/optics/typeclasses/Index { } public final class arrow/optics/typeclasses/Index$Companion { - public final fun fromIso (Larrow/optics/typeclasses/Index;Larrow/optics/PIso;)Larrow/optics/typeclasses/Index; public final fun list ()Larrow/optics/typeclasses/Index; public final fun map ()Larrow/optics/typeclasses/Index; public final fun nonEmptyList ()Larrow/optics/typeclasses/Index; @@ -902,19 +500,9 @@ public final class arrow/optics/typeclasses/Index$Companion { } public final class arrow/optics/typeclasses/Index$DefaultImpls { - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public static fun get (Larrow/optics/typeclasses/Index;Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/Fold;Ljava/lang/Object;)Larrow/optics/Fold; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PIso;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PLens;Ljava/lang/Object;)Larrow/optics/POptional; public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/POptional;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PPrism;Ljava/lang/Object;)Larrow/optics/POptional; - public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PSetter;Ljava/lang/Object;)Larrow/optics/PSetter; public static fun index (Larrow/optics/typeclasses/Index;Larrow/optics/PTraversal;Ljava/lang/Object;)Larrow/optics/PTraversal; } @@ -931,7 +519,6 @@ public abstract interface class arrow/optics/typeclasses/Snoc { } public final class arrow/optics/typeclasses/Snoc$Companion { - public final fun fromIso (Larrow/optics/typeclasses/Snoc;Larrow/optics/PIso;)Larrow/optics/typeclasses/Snoc; public final fun invoke (Larrow/optics/PPrism;)Larrow/optics/typeclasses/Snoc; public final fun list ()Larrow/optics/typeclasses/Snoc; public final fun string ()Larrow/optics/typeclasses/Snoc; From 7c5b8f308147eab7005e7eef0884b6ac18af6975 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 15 Dec 2022 13:24:11 +0100 Subject: [PATCH 09/11] Small thing --- .../src/commonMain/kotlin/arrow/optics/typeclasses/At.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt index 07258def13c..9f96d1648b7 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/typeclasses/At.kt @@ -32,8 +32,7 @@ public fun interface At { * @param i index [I] to zoom into [S] and find focus [A] * @return [Lens] with a focus in [A] at given index [I]. */ - public fun Lens.at(i: I): Lens = - this@at.compose(this@At.at(i)) + public fun Lens.at(i: I): Lens = this@at.compose(this@At.at(i)) /** * DSL to compose [At] with an [Optional] for a structure [S] to focus in on [A] at given index [I]. From 54540b3ec9f7a0467f746aaec47a9cfdb8e5ad29 Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Thu, 15 Dec 2022 13:46:36 +0100 Subject: [PATCH 10/11] Missing Knit example --- .../kotlin/examples/example-optional-01.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt diff --git a/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt new file mode 100644 index 00000000000..f9d299003a7 --- /dev/null +++ b/arrow-libs/optics/arrow-optics/src/commonTest/kotlin/examples/example-optional-01.kt @@ -0,0 +1,23 @@ +// This file was automatically generated from Optional.kt by Knit tool. Do not edit. +package arrow.optics.examples.exampleOptional01 + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import arrow.optics.Optional + +data class User(val username: String, val email: Option) { + companion object { + // can be out generated by @optics + val email: Optional = Optional(User::email) { user, email -> + user.copy(email = Some(email)) + } + } +} + +fun main(args: Array) { + val original = User("arrow-user", None) + val set = User.email.set(original, "arRoW-UsEr@arrow-Kt.IO") + val modified = User.email.modify(set, String::toLowerCase) + println("original: $original, set: $set, modified: $modified") +} From e60c86ead1beb69a484c27fefdaedabcde85281f Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Wed, 21 Dec 2022 14:12:35 +0100 Subject: [PATCH 11/11] Remove unnecessary method --- arrow-libs/optics/arrow-optics/api/arrow-optics.api | 1 - .../src/commonMain/kotlin/arrow/optics/dsl/index.kt | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/arrow-libs/optics/arrow-optics/api/arrow-optics.api b/arrow-libs/optics/arrow-optics/api/arrow-optics.api index b57071ebd62..6c6d664c124 100644 --- a/arrow-libs/optics/arrow-optics/api/arrow-optics.api +++ b/arrow-libs/optics/arrow-optics/api/arrow-optics.api @@ -394,7 +394,6 @@ public final class arrow/optics/dsl/EveryKt { } public final class arrow/optics/dsl/IndexKt { - public static final fun index (Larrow/optics/PLens;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; public static final fun index (Larrow/optics/POptional;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/POptional; public static final fun index (Larrow/optics/PTraversal;Larrow/optics/typeclasses/Index;Ljava/lang/Object;)Larrow/optics/PTraversal; } diff --git a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt index 61f5b0a5385..ca7ff58db85 100644 --- a/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt +++ b/arrow-libs/optics/arrow-optics/src/commonMain/kotlin/arrow/optics/dsl/index.kt @@ -6,20 +6,10 @@ import arrow.optics.Prism import arrow.optics.Traversal import arrow.optics.typeclasses.Index -/** - * DSL to compose [Index] with a [Lens] for a structure [S] to focus in on [A] at given index [I] - * - * @receiver [Lens] with a focus in [S] - * @param idx [Index] instance to provide a [Optional] to focus into [S] at [I] - * @param i index [I] to focus into [S] and find focus [A] - * @return [Optional] with a focus in [A] at given index [I] - */ -public fun Lens.index(idx: Index, i: I): Optional = this.compose(idx.index(i)) - /** * DSL to compose [Index] with an [Optional] for a structure [S] to focus in on [A] at given index [I] * - * @receiver [Optional] or [Prism] with a focus in [S] + * @receiver [Optional], [Lens], or [Prism] with a focus in [S] * @param idx [Index] instance to provide a [Optional] to focus into [S] at [I] * @param i index [I] to focus into [S] and find focus [A] * @return [Optional] with a focus in [A] at given index [I]