Skip to content

Commit

Permalink
Deprecate foldMap with Monoid in Fold
Browse files Browse the repository at this point in the history
  • Loading branch information
gutiory committed Mar 28, 2023
1 parent 36db03e commit 659c080
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 9 deletions.
9 changes: 7 additions & 2 deletions arrow-libs/optics/arrow-optics/api/arrow-optics.api
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public final class arrow/optics/Fold$DefaultImpls {
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 All @@ -105,6 +104,7 @@ public abstract interface class arrow/optics/Getter : arrow/optics/Fold {
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 foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down Expand Up @@ -173,6 +173,7 @@ public abstract interface class arrow/optics/PEvery : arrow/optics/Fold, arrow/o
public abstract fun compose (Larrow/optics/PEvery;)Larrow/optics/PEvery;
public static fun either ()Larrow/optics/PEvery;
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 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;
Expand Down Expand Up @@ -234,7 +235,6 @@ public final class arrow/optics/PEvery$DefaultImpls {
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 @@ -264,6 +264,7 @@ public abstract interface class arrow/optics/PIso : arrow/optics/Fold, arrow/opt
public static fun eitherToValidated ()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 foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down Expand Up @@ -385,6 +386,7 @@ public abstract interface class arrow/optics/PLens : arrow/optics/Getter, arrow/
public abstract fun compose (Larrow/optics/PLens;)Larrow/optics/PLens;
public abstract fun first ()Larrow/optics/PLens;
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 get (Ljava/lang/Object;)Ljava/lang/Object;
public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either;
public static fun nonEmptyListHead ()Larrow/optics/PLens;
Expand Down Expand Up @@ -490,6 +492,7 @@ public abstract interface class arrow/optics/POptional : arrow/optics/PEvery, ar
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 foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public abstract fun getOrModify (Ljava/lang/Object;)Larrow/core/Either;
public static fun listHead ()Larrow/optics/POptional;
public static fun listTail ()Larrow/optics/POptional;
Expand Down Expand Up @@ -570,6 +573,7 @@ public abstract interface class arrow/optics/POptionalGetter : arrow/optics/Fold
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 foldMap (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;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;
Expand Down Expand Up @@ -618,6 +622,7 @@ public abstract interface class arrow/optics/PPrism : arrow/optics/PEvery, arrow
public static fun eitherRight ()Larrow/optics/PPrism;
public abstract fun first ()Larrow/optics/PPrism;
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 getOrModify (Ljava/lang/Object;)Larrow/core/Either;
public abstract fun left ()Larrow/optics/PPrism;
public abstract fun liftNullable (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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: S, map: (focus: A) -> R): R

override fun <R> foldMap(empty: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R

override fun modify(source: S, map: (focus: A) -> B): T

/**
Expand All @@ -40,6 +42,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette

override fun modify(source: S, map: (focus: C) -> D): T =
this@PEvery.modify(source) { b -> other.modify(b, map) }

override fun <R> foldMap(empty: R, combine: (R, R) -> R, source: S, map: (focus: C) -> R): R =
this@PEvery.foldMap(empty, combine, source) { c -> other.foldMap(empty, combine, c, map) }
}

public operator fun <C, D> plus(other: PEvery<in A, out B, out C, in D>): PEvery<S, T, C, D> =
Expand All @@ -50,6 +55,8 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
object : Every<S, A> {
override fun <R> foldMap(M: Monoid<R>, 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)
override fun <R> foldMap(empty: R, combine: (R, R) -> R, source: S, map: (focus: A) -> R): R =
F.foldMap(empty, combine, source, map)
}

/**
Expand All @@ -63,6 +70,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette

override fun <R> foldMap(M: Monoid<R>, source: List<A>, map: (focus: A) -> R): R =
source.foldMap(M, map)

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

/**
Expand All @@ -78,6 +88,10 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette

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

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

}

@JvmStatic
Expand All @@ -89,6 +103,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
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(empty: R, combine: (R, R) -> R, source: Map<K, V>, map: (focus: V) -> R): R =
source.fold(empty) { acc, (_, v) -> combine(acc, map(v)) }
}

/**
Expand All @@ -105,6 +122,10 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette

override fun <R> foldMap(M: Monoid<R>, source: NonEmptyList<A>, map: (focus: A) -> R): R =
source.foldMap(M, map)

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

}

/**
Expand All @@ -121,6 +142,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette

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

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

@JvmStatic
Expand All @@ -131,6 +155,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette

override fun <R> foldMap(M: Monoid<R>, source: Sequence<A>, map: (focus: A) -> R): R =
source.foldMap(M, map)

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

/**
Expand All @@ -148,6 +175,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
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(empty: R, combine: (R, R) -> R, source: String, map: (focus: Char) -> R): R =
source.fold(empty) { acc, char -> combine(acc, map(char)) }
}

/**
Expand All @@ -162,6 +192,10 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
override fun <R> foldMap(M: Monoid<R>, source: Pair<A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second)
.foldMap(M, map)

override fun <R> foldMap(empty: R, combine: (R, R) -> R, source: Pair<A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second).fold(empty) { acc, a -> combine(acc, map(a)) }

}

/**
Expand All @@ -176,6 +210,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
override fun <R> foldMap(M: Monoid<R>, source: Triple<A, A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second, source.third)
.foldMap(M, map)

override fun <R> foldMap(empty: R, combine: (R, R) -> R, source: Triple<A, A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second, source.third).fold(empty) { acc, a -> combine(acc, map(a)) }
}

/**
Expand All @@ -190,6 +227,9 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
override fun <R> foldMap(M: Monoid<R>, source: Tuple4<A, A, A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second, source.third, source.fourth)
.foldMap(M, map)

override fun <R> foldMap(empty: R, combine: (R, R) -> R, source: Tuple4<A, A, A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second, source.third, source.fourth).fold(empty) { acc, a -> combine(acc, map(a))}
}

/**
Expand All @@ -204,6 +244,15 @@ public interface PEvery<S, T, A, B> : PTraversal<S, T, A, B>, Fold<S, A>, PSette
override fun <R> foldMap(M: Monoid<R>, source: Tuple5<A, A, A, A, A>, map: (focus: A) -> R): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth)
.foldMap(M, map)

override fun <R> foldMap(
empty: R,
combine: (R, R) -> R,
source: Tuple5<A, A, A, A, A>,
map: (focus: A) -> R
): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth)
.fold(empty) { acc, a -> combine(acc, map(a)) }
}

/**
Expand All @@ -225,6 +274,15 @@ 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 =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth)
.foldMap(M, map)

override fun <R> foldMap(
empty: R,
combine: (R, R) -> R,
source: Tuple6<A, A, A, A, A, A>,
map: (focus: A) -> R
): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth)
.fold(empty) { acc, a -> combine(acc, map(a)) }
}

/**
Expand All @@ -247,6 +305,15 @@ 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 =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh)
.foldMap(M, map)

override fun <R> foldMap(
empty: R,
combine: (R, R) -> R,
source: Tuple7<A, A, A, A, A, A, A>,
map: (focus: A) -> R
): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh)
.fold(empty) { acc, a -> combine(acc, map(a)) }
}

/**
Expand All @@ -273,6 +340,15 @@ 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 =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth)
.foldMap(M, map)

override fun <R> foldMap(
empty: R,
combine: (R, R) -> R,
source: Tuple8<A, A, A, A, A, A, A, A>,
map: (focus: A) -> R
): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth)
.fold(empty) { acc, a -> combine(acc, map(a)) }
}

/**
Expand Down Expand Up @@ -300,6 +376,15 @@ 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 =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth)
.foldMap(M, map)

override fun <R> foldMap(
empty: R,
combine: (R, R) -> R,
source: Tuple9<A, A, A, A, A, A, A, A, A>,
map: (focus: A) -> R
): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth)
.fold(empty) { acc, a -> combine(acc, map(a)) }
}

/**
Expand Down Expand Up @@ -328,6 +413,15 @@ 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 =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth, source.tenth)
.foldMap(M, map)

override fun <R> foldMap(
empty: R,
combine: (R, R) -> R,
source: Tuple10<A, A, A, A, A, A, A, A, A, A>,
map: (focus: A) -> R
): R =
listOf(source.first, source.second, source.third, source.fourth, source.fifth, source.sixth, source.seventh, source.eighth, source.ninth, source.tenth)
.fold(empty) { acc, a -> combine(acc, map(a)) }
}
}

Expand Down
Loading

0 comments on commit 659c080

Please sign in to comment.