Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Deprecate map2 and product in favor of zip #311

Merged
merged 21 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2037e20
Start deprecating map2 and product in favor of zip for Apply, Either,…
danimontoya Jan 21, 2021
a6f02b7
Moving Either.zip to right the place and updating Either, Iterable an…
danimontoya Jan 21, 2021
f3d89b5
Replace Iterable.zip definition with zip from kotlin std
danimontoya Jan 22, 2021
888ac74
Apply doesnt need to be updated (will be removed)
danimontoya Jan 22, 2021
962181e
Update Either
danimontoya Jan 22, 2021
dc61993
This can simply be removed since it didn't exist in 0.11.0
danimontoya Jan 22, 2021
11f8061
These were not available in 0.11.0 and can be removed and replaced wi…
danimontoya Jan 22, 2021
acdb238
Option.zip functions
danimontoya Jan 22, 2021
4bc199c
Update Either, EitherApply and Validated based on @nomisRev PR
danimontoya Jan 22, 2021
7d2c61e
KtLint
danimontoya Jan 22, 2021
7f9357e
Merge branch 'master' into dm-deprecate-map2-to-zip
danimontoya Jan 22, 2021
c72ad8a
Remove duplicate due to merge
danimontoya Jan 22, 2021
5fbe326
Deprecate Option.map2 in favor of zip
danimontoya Jan 22, 2021
3192718
Missing import ...
danimontoya Jan 22, 2021
1443dc4
Merge branch 'master' into dm-deprecate-map2-to-zip
danimontoya Jan 25, 2021
536e92e
Update Either and Option deprecation messages for map2
danimontoya Jan 25, 2021
f6c505b
Update EitherApply deprecation messages for map2 and product
danimontoya Jan 25, 2021
484486f
Add zip definition for Eval, Ior and NonEmptyList
danimontoya Jan 25, 2021
abf6609
Update NonEmptyList.zip
danimontoya Jan 25, 2021
29d78ac
Apply suggestions from code review
danimontoya Jan 25, 2021
7bddf52
Merge branch 'master' into dm-deprecate-map2-to-zip
i-walker Jan 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions arrow-core-data/src/main/kotlin/arrow/core/Either.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1855,11 +1855,23 @@ fun <A, C, B : C> Either<A, B>.widen(): Either<A, C> =
fun <AA, A : AA, B> Either<A, B>.leftWiden(): Either<AA, B> =
this

@Deprecated(
"Instead of product, please use zip",
ReplaceWith(
"zip(fb)"
danimontoya marked this conversation as resolved.
Show resolved Hide resolved
)
)
fun <A, B, C> Either<A, B>.product(fb: Either<A, C>): Either<A, Tuple2<B, C>> =
flatMap { a ->
fb.map { b -> Tuple2(a, b) }
}

@Deprecated(
"Instead of map2, please use zip",
ReplaceWith(
"zip(fb, f)"
)
)
fun <A, B, C, D> Either<A, B>.map2(fb: Either<A, C>, f: (Tuple2<B, C>) -> D): Either<A, D> =
product(fb).map(f)

Expand Down
12 changes: 12 additions & 0 deletions arrow-core-data/src/main/kotlin/arrow/core/Iterable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ fun <E, A> Iterable<Validated<E, Iterable<A>>>.flatSequenceValidated(semigroup:
fun <E> Iterable<Validated<E, *>>.sequenceValidated_(semigroup: Semigroup<E>): Validated<E, Unit> =
traverseValidated_(semigroup, ::identity)

@Deprecated(
"Instead of map2, please use zip",
ReplaceWith(
"zip(fb, f)"
)
)
inline fun <A, B, Z> Iterable<A>.map2(fb: Iterable<B>, f: (Tuple2<A, B>) -> Z): List<Z> =
flatMap { a ->
fb.map { b ->
Expand Down Expand Up @@ -450,6 +456,12 @@ fun <A, B> Iterable<Ior<A, B>>.unalign(): Tuple2<List<A>, List<B>> =
inline fun <A, B, C> Iterable<C>.unalign(fa: (C) -> Ior<A, B>): Tuple2<List<A>, List<B>> =
map(fa).unalign()

@Deprecated(
"Instead of product, please use zip",
ReplaceWith(
"zip(fb)"
)
)
fun <A, B> Iterable<A>.product(fb: Iterable<B>): List<Tuple2<A, B>> =
fb.ap(map { a: A -> { b: B -> Tuple2(a, b) } })

Expand Down
12 changes: 12 additions & 0 deletions arrow-core-data/src/main/kotlin/arrow/core/Validated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1111,9 +1111,21 @@ fun <E, A> Validated<E, A>.replicate(SE: Semigroup<E>, n: Int, MA: Monoid<A>): V
if (n <= 0) MA.empty().valid()
else Validated.mapN(SE, this@replicate, replicate(SE, n - 1, MA)) { a, xs -> MA.run { a + xs } }

@Deprecated(
"Instead of product, please use zip",
ReplaceWith(
"zip(SE, fb)"
danimontoya marked this conversation as resolved.
Show resolved Hide resolved
)
)
fun <E, A, B> Validated<E, A>.product(SE: Semigroup<E>, fb: Validated<E, B>): Validated<E, Tuple2<A, B>> =
ap(SE, fb.map { b: B -> { a: A -> Tuple2(a, b) } })

@Deprecated(
"Instead of map2, please use zip",
ReplaceWith(
"zip(SE, fb, f)"
danimontoya marked this conversation as resolved.
Show resolved Hide resolved
)
)
fun <E, A, B, Z> Validated<E, A>.map2(SE: Semigroup<E>, fb: Validated<E, B>, f: (Tuple2<A, B>) -> Z): Validated<E, Z> =
product(SE, fb).map(f)
danimontoya marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
12 changes: 12 additions & 0 deletions arrow-core-data/src/main/kotlin/arrow/typeclasses/Apply.kt
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,21 @@ interface Apply<F> : Functor<F> {
a.product(b).product(c).product(d).product(e).product(f)
.product(g).product(h).product(i).product(j).map(lbd)

@Deprecated(
"Instead of map2, please use zip",
ReplaceWith(
"zip(fb, f)"
)
)
fun <A, B, Z> Kind<F, A>.map2(fb: Kind<F, B>, f: (Tuple2<A, B>) -> Z): Kind<F, Z> =
product(fb).map(f)

@Deprecated(
"Instead of product, please use zip",
ReplaceWith(
"zip(fb)"
)
)
fun <A, B> Kind<F, A>.product(fb: Kind<F, B>): Kind<F, Tuple2<A, B>> =
ap(fb.map { b: B -> { a: A -> Tuple2(a, b) } })

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package arrow.core.extensions.either.zip

import arrow.core.Either
import arrow.core.Tuple2

@JvmName("zip")
@Suppress(
"UNCHECKED_CAST",
"USELESS_CAST",
"EXTENSION_SHADOWED_BY_MEMBER",
"UNUSED_PARAMETER"
)
@Deprecated(
"@extension projected functions are deprecated",
ReplaceWith(
"this.zip(arg1, ::Tuple2)",
"arrow.core.zip", "arrow.core.Tuple2"
),
DeprecationLevel.WARNING
)
fun <A, B, E> Either<E, A>.zip(arg1: Either<E, B>): Either<E, Tuple2<A, B>> =
danimontoya marked this conversation as resolved.
Show resolved Hide resolved
TODO()

@JvmName("zipWith")
@Suppress(
"UNCHECKED_CAST",
"USELESS_CAST",
"EXTENSION_SHADOWED_BY_MEMBER",
"UNUSED_PARAMETER"
)
@Deprecated(
"@extension projected functions are deprecated",
ReplaceWith(
"this.zip(arg1, arg2)",
"arrow.core.zip"
),
DeprecationLevel.WARNING
)
fun <A, B, C, E> Either<E, A>.zipWith(arg1: Either<E, B>, arg2: Function2<A, B, C>): Either<E, C> =
TODO()
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ internal val zip_singleton: OptionZip = object : arrow.core.extensions.OptionZip
@Deprecated(
"@extension kinded projected functions are deprecated",
ReplaceWith(
"zip(arg1)",
"arrow.core.zip"
"zip(arg1)",
"arrow.core.zip"
danimontoya marked this conversation as resolved.
Show resolved Hide resolved
),
DeprecationLevel.WARNING
)
fun <A, B> Kind<ForOption, A>.zip(arg1: Kind<ForOption, B>): Option<Tuple2<A, B>> =
arrow.core.Option.zip().run {
this@zip.zip<A, B>(arg1) as arrow.core.Option<arrow.core.Tuple2<A, B>>
}
arrow.core.Option.zip().run {
this@zip.zip<A, B>(arg1) as arrow.core.Option<arrow.core.Tuple2<A, B>>
}

@JvmName("zipWith")
@Suppress(
Expand All @@ -48,15 +48,15 @@ fun <A, B> Kind<ForOption, A>.zip(arg1: Kind<ForOption, B>): Option<Tuple2<A, B>
@Deprecated(
"@extension kinded projected functions are deprecated",
ReplaceWith(
"zipWith(arg1, arg2)",
"arrow.core.zipWith"
"zipWith(arg1, arg2)",
"arrow.core.zipWith"
danimontoya marked this conversation as resolved.
Show resolved Hide resolved
),
DeprecationLevel.WARNING
)
fun <A, B, C> Kind<ForOption, A>.zipWith(arg1: Kind<ForOption, B>, arg2: Function2<A, B, C>):
Option<C> = arrow.core.Option.zip().run {
this@zipWith.zipWith<A, B, C>(arg1, arg2) as arrow.core.Option<C>
}
fun <A, B, C> Kind<ForOption, A>.zipWith(arg1: Kind<ForOption, B>, arg2: Function2<A, B, C>): Option<C> =
arrow.core.Option.zip().run {
this@zipWith.zipWith<A, B, C>(arg1, arg2) as arrow.core.Option<C>
}

@Suppress(
"UNCHECKED_CAST",
Expand Down