Skip to content

Commit ce8f69b

Browse files
Deprecate @higherkind & @extension for Validated and offer concrete implementations (#267)
* Remove @higherkind generation, and deprecate generated code * Remove @extensions for Validated Eq * Deprecate @extension and add missing concrete implementations * Add show on Companion of Validated * Add order on Companion of Validated * Remove dummy params from product * Add deprecation to last methods * Rewrite Validated branch * Fix concrete bifoldable signatures * ktlintFormat & fix docs * Revert refactor from suspend Validated.catch to inline Validated.catch * ktlintFormat * Revert refactor from suspend Validated.catch to inline Validated.catch * Fix incorrect import * Add missing , in Validated docs * Validated.kt doc fromOption -> fromNullable * Docs green locally * Re-add `unit` and make `DeprecatedLevel.ERROR` * Remove TupleN from mapN signature * Revert "Re-add `unit` and make `DeprecatedLevel.ERROR`, not possible due to @extensions" This reverts commit c540118a09cbbb5e7cbef9566b9465e8bccc8138. * ktlintFormat * Fix Validated.mapN docs * Retrigger build * Update type arguments names, and param names * Replace suspend catch with inline catch while maintaining binary compat Co-authored-by: Rachel M. Carmena <[email protected]>
1 parent ccfe8b4 commit ce8f69b

File tree

28 files changed

+2514
-315
lines changed

28 files changed

+2514
-315
lines changed

arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,6 @@ sealed class Either<out A, out B> : EitherOf<A, B> {
869869
* Left(12).map { "flower" } // Result: Left(12)
870870
* ```
871871
*/
872-
@Suppress("UNCHECKED_CAST")
873872
inline fun <C> map(f: (B) -> C): Either<A, C> =
874873
flatMap { Right(f(it)) }
875874

@@ -996,6 +995,12 @@ sealed class Either<out A, out B> : EitherOf<A, B> {
996995

997996
fun <R> right(right: R): Either<Nothing, R> = Right(right)
998997

998+
val leftUnit: Either<Unit, Nothing> = left(Unit)
999+
1000+
val unit: Either<Nothing, Unit> = right(Unit)
1001+
1002+
fun <L> unit(): Either<L, Unit> = unit
1003+
9991004
fun <A> fromNullable(a: A?): Either<Unit, A> = a?.right() ?: Unit.left()
10001005

10011006
tailrec fun <L, A, B> tailRecM(a: A, f: (A) -> Kind<EitherPartialOf<L>, Either<A, B>>): Either<L, B> {
@@ -1077,6 +1082,12 @@ sealed class Either<out A, out B> : EitherOf<A, B> {
10771082
.fold({ t: Throwable -> throwable(t) }, { b: B -> b.right() })
10781083
.fold({ t: Throwable -> unrecoverableState(t); throw t }, { b: B -> b })
10791084
}
1085+
1086+
fun <C> mapConst(c: C): Either<A, C> =
1087+
map { c }
1088+
1089+
fun void(): Either<A, Unit> =
1090+
mapConst(Unit)
10801091
}
10811092

10821093
fun <L> Left(left: L): Either<L, Nothing> = Left(left)

arrow-libs/core/arrow-core-data/src/main/kotlin/arrow/core/ListK.kt

+6
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,9 @@ fun <A> List<A>.k(): ListK<A> = ListK(this)
482482

483483
fun <A> listKOf(vararg elements: A): ListK<A> =
484484
listOf(*elements).k()
485+
486+
fun <A, B> Iterable<A>.mapConst(b: B): List<B> =
487+
map { b }
488+
489+
fun <A> Iterable<A>.void(): List<Unit> =
490+
mapConst(Unit)

0 commit comments

Comments
 (0)