Skip to content

Commit

Permalink
Deprecate Monoid and Semigroup in Optics (#2985)
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Mar 24, 2023
1 parent 2c9489a commit 61e10d8
Show file tree
Hide file tree
Showing 48 changed files with 307 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface Monoid<A> : Semigroup<A> {
public fun fold(elems: List<A>): A = elems.fold()

public companion object {

@JvmStatic
@JvmName("Boolean")
public fun boolean(): Monoid<Boolean> = AndMonoid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package arrow.core.test.laws
import arrow.core.test.Law
import arrow.core.test.LawSet
import arrow.core.test.equalUnderTheLaw
import arrow.typeclasses.Monoid
import io.kotest.property.Arb
import io.kotest.property.checkAll
import io.kotest.matchers.shouldBe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package arrow.core.test.laws
import arrow.core.test.Law
import arrow.core.test.LawSet
import arrow.core.test.equalUnderTheLaw
import arrow.typeclasses.Semigroup
import io.kotest.property.Arb
import io.kotest.property.PropertyContext
import io.kotest.property.checkAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package arrow.core.test.laws
import arrow.core.test.Law
import arrow.core.test.LawSet
import arrow.core.test.equalUnderTheLaw
import arrow.typeclasses.Semiring
import io.kotest.property.Arb
import io.kotest.property.checkAll
import io.kotest.matchers.shouldBe
import io.kotest.property.PropertyContext

data class SemiringLaws<F>(
val zero: F,
Expand Down
18 changes: 18 additions & 0 deletions arrow-libs/optics/arrow-optics/api/arrow-optics.api
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public abstract interface class arrow/optics/Fold {
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 fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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
Expand Down Expand Up @@ -85,6 +87,8 @@ public final class arrow/optics/Fold$DefaultImpls {
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 fold (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object;
public static fun foldMap (Larrow/optics/Fold;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)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
Expand Down Expand Up @@ -128,7 +132,9 @@ public final class arrow/optics/Getter$DefaultImpls {
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 fold (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Larrow/optics/Getter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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
Expand Down Expand Up @@ -227,6 +233,8 @@ public final class arrow/optics/PEvery$DefaultImpls {
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 fold (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;)Ljava/lang/Object;
public static fun foldMap (Larrow/optics/PEvery;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)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;
Expand Down Expand Up @@ -327,7 +335,9 @@ public final class arrow/optics/PIso$DefaultImpls {
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 fold (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Larrow/optics/PIso;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down Expand Up @@ -437,7 +447,9 @@ public final class arrow/optics/PLens$DefaultImpls {
public static fun first (Larrow/optics/PLens;)Larrow/optics/PLens;
public static fun firstOrNull (Larrow/optics/PLens;Ljava/lang/Object;)Ljava/lang/Object;
public static fun fold (Larrow/optics/PLens;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object;
public static fun fold (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Larrow/optics/PLens;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down Expand Up @@ -520,7 +532,9 @@ public final class arrow/optics/POptional$DefaultImpls {
public static fun first (Larrow/optics/POptional;)Larrow/optics/POptional;
public static fun firstOrNull (Larrow/optics/POptional;Ljava/lang/Object;)Ljava/lang/Object;
public static fun fold (Larrow/optics/POptional;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object;
public static fun fold (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Larrow/optics/POptional;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down Expand Up @@ -581,7 +595,9 @@ public final class arrow/optics/POptionalGetter$DefaultImpls {
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 fold (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Larrow/optics/POptionalGetter;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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
Expand Down Expand Up @@ -653,7 +669,9 @@ public final class arrow/optics/PPrism$DefaultImpls {
public static fun first (Larrow/optics/PPrism;)Larrow/optics/PPrism;
public static fun firstOrNull (Larrow/optics/PPrism;Ljava/lang/Object;)Ljava/lang/Object;
public static fun fold (Larrow/optics/PPrism;Larrow/typeclasses/Monoid;Ljava/lang/Object;)Ljava/lang/Object;
public static fun fold (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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 foldMap (Larrow/optics/PPrism;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
/**
* [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
Expand All @@ -78,7 +77,7 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
source.map(map)

override fun <A> foldMap(M: Monoid<A>, source: Either<L, R>, map: (focus: R) -> A): A =
source.foldMap(M, map)
source.fold({ M.empty() }, map)
}

@JvmStatic
Expand All @@ -87,12 +86,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
override fun modify(source: Map<K, V>, map: (focus: V) -> V): Map<K, V> =
source.mapValues { (_, v) -> map(v) }

override fun <R> foldMap(M: Monoid<R>, source: Map<K, V>, map: (focus: V) -> R): R =
M.run {
source.fold(empty()) { acc, (_, v) ->
acc.combine(map(v))
}
}
override fun <R> foldMap(M: Monoid<R>, source: Map<K, V>, map: (focus: V) -> R): R = M.run {
source.fold(empty()) { acc, (_, v) -> acc.combine(map(v)) }
}
}

/**
Expand Down Expand Up @@ -124,7 +120,7 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
source.map(map)

override fun <R> foldMap(M: Monoid<R>, source: Option<A>, map: (focus: A) -> R): R =
source.foldMap(M, map)
source.fold({ M.empty() }, map)
}

@JvmStatic
Expand All @@ -134,11 +130,7 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
source.map(map)

override fun <R> foldMap(M: Monoid<R>, source: Sequence<A>, map: (focus: A) -> R): R =
M.run {
source.fold(empty()) { acc, a ->
acc.combine(map(a))
}
}
source.foldMap(M, map)
}

/**
Expand All @@ -153,10 +145,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
override fun modify(source: String, map: (focus: Char) -> Char): String =
source.map(map).joinToString(separator = "")

override fun <R> foldMap(M: Monoid<R>, source: String, map: (focus: Char) -> R): R =
M.run {
source.fold(empty()) { acc, char -> acc.combine(map(char)) }
}
override fun <R> foldMap(M: Monoid<R>, source: String, map: (focus: Char) -> R): R = M.run {
source.fold(empty()) { acc, char -> acc.combine(map(char)) }
}
}

/**
Expand All @@ -169,9 +160,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
Pair(map(source.first), map(source.second))

override fun <R> foldMap(M: Monoid<R>, source: Pair<A, A>, map: (focus: A) -> R): R =
M.run {
map(source.first).combine(map(source.second))
}
listOf(source.first, source.second)
.foldMap(M, map)
}

/**
Expand All @@ -184,11 +174,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
Triple(map(source.first), map(source.second), map(source.third))

override fun <R> foldMap(M: Monoid<R>, source: Triple<A, A, A>, map: (focus: A) -> R): R =
M.run {
map(source.first)
.combine(map(source.second))
.combine(map(source.third))
}
listOf(source.first, source.second, source.third)
.foldMap(M, map)
}

/**
Expand All @@ -201,12 +188,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
Tuple4(map(source.first), map(source.second), map(source.third), map(source.fourth))

override fun <R> foldMap(M: Monoid<R>, source: Tuple4<A, A, A, A>, map: (focus: A) -> R): R =
M.run {
map(source.first)
.combine(map(source.second))
.combine(map(source.third))
.combine(map(source.fourth))
}
listOf(source.first, source.second, source.third, source.fourth)
.foldMap(M, map)
}

/**
Expand All @@ -219,13 +202,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
Tuple5(map(source.first), map(source.second), map(source.third), map(source.fourth), map(source.fifth))

override fun <R> foldMap(M: Monoid<R>, source: Tuple5<A, A, A, A, A>, 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))
}
listOf(source.first, source.second, source.third, source.fourth, source.fifth)
.foldMap(M, map)
}

/**
Expand All @@ -245,14 +223,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
)

override fun <R> foldMap(M: Monoid<R>, source: Tuple6<A, A, A, A, A, A>, 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))
}
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth)
.foldMap(M, map)
}

/**
Expand All @@ -273,15 +245,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
)

override fun <R> foldMap(M: Monoid<R>, source: Tuple7<A, A, A, A, A, A, A>, 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))
}
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh)
.foldMap(M, map)
}

/**
Expand All @@ -306,16 +271,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
)

override fun <R> foldMap(M: Monoid<R>, source: Tuple8<A, A, A, A, A, A, A, A>, 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))
}
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth)
.foldMap(M, map)
}

/**
Expand All @@ -341,17 +298,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
)

override fun <R> foldMap(M: Monoid<R>, source: Tuple9<A, A, A, A, A, A, A, A, A>, 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))
}
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth)
.foldMap(M, map)
}

/**
Expand All @@ -378,18 +326,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
)

override fun <R> foldMap(M: Monoid<R>, source: Tuple10<A, A, A, A, A, A, A, A, A, A>, 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))
}
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth, source.tenth)
.foldMap(M, map)
}
}

Expand Down
Loading

0 comments on commit 61e10d8

Please sign in to comment.