-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PROPOSAL] Ior API deprecation, and preparation for 2.x.x #2928
Conversation
Kover Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @gutiory 🙌 Thank you so much for looking into this! I added a bunch of suggestions 😅 Feel free to apply them, or use them as a guide to update the PR. Whatever works best for you.
ReplaceWith
is missing imports, addedIor.
in most cases to avoid conflicts withEither.Left
&Either.Right
.- A bunch of
identity
calls slipped in due to refactoring tools of IDEA. - Some styling nits (Spaces before
{
mostly). - Small improvements to
foldLeft
andbifold
,empty + a == a
forMonoid
so theReplaceWith
can be simplified.
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
@Deprecated( | ||
NicheAPI + "Prefer when or fold instead", | ||
ReplaceWith("fold({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) })") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReplaceWith("fold({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) })") | |
ReplaceWith("this.fold<C>({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) })") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Why is it needed here the this.fold<C>
part?. I've tried a couple of replacement and the result is the same than using the current solution.
This comment follows the conventionalcomments.org standard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replacement was not working for me as is :/
Just adding this
is sufficient, it's strange it works for foldMap
, without this
.
So the <C>
can be ignored, IIRC adding it adds a type-check during replacement that checks if the resulting replacement is correct in cases where it otherwise is incorrect but it's not entirely clear to me when it's needed and when not. Similar in this case for this
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 74ef6ec
(#2928)
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Simon Vergauwen <nomisRev@users.noreply.github.com>
Alternative methods with `predicate` function parameter is added for every method. `isNotEmpty()` replacement was incorrect.
…ther` `Both` is prepend with `Ior.` as well, to keep communality within the code. Missing imports are added in the `ReplaceWith` class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to keep you waiting for so long @gutiory. Thanks for all the great work so far 🙌
Couple of things we still need to address, that I missed in the first review:
- We missed a couple of deprecations:
-
isRight
,isLeft
, &isBoth
properties -
toValidated
-
bitraverseValidated
,bisequenceValidated
-
replicate
-
we should align
getOrElse
function with the other signatures. This can be done without deprecation, in a source -and binary compatible way.Either.getOrElse
{ },Either.getOrElse { _ -> }
. -
We need to introduce
getLeftOrNull
similarly togetOrNull
and deprecate the currentleftOrNull
method. Similarly I would love to have a better name forpadNull
butgetBothOrNull
seems wrong since it returnsPair<A?, B?>
🤔
I've tested a couple of the ReplaceWith
, and left comments. Also resolved some of the previous comments that were still open.
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
@Deprecated( | ||
NicheAPI + "Prefer when or fold instead", | ||
ReplaceWith("fold({ f(c, it) }, { g(c, it) }, { a, b -> g(f(c, a), b) })") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This replacement was not working for me as is :/
Just adding this
is sufficient, it's strange it works for foldMap
, without this
.
So the <C>
can be ignored, IIRC adding it adds a type-check during replacement that checks if the resulting replacement is correct in cases where it otherwise is incorrect but it's not entirely clear to me when it's needed and when not. Similar in this case for this
.
All vals must still be public and the `JVM` name of the respective methods must differ due to a clash when generating the apiDump
`leftOrNull` follows Kotlin std convention like in https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-result/exception-or-null.html
Give `toNullablePair` a more meaningful name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks really great! Thank you for all the hard work, and a lot of patience @gutiory. 🙏 👏 👏 👏
Let's merge this this 🙌
@Deprecated( | ||
"leftOrNull is being renamed to getOrNull to be more consistent with the Kotlin Standard Library naming", | ||
ReplaceWith("getLeftOrNull()") | ||
) | ||
public fun leftOrNull(): A? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, to completely track decision making on this. Result
from Kotlin Std has exceptionOrNull
alongside getOrNull
instead of getExceptionOrNull
so we're following the same API naming pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @gutiory!
Ior API deprecation
This PR proposes a smaller API surface for
Ior
without compromising its functionality or feature set.The goal of these changes is to offer APIs that are more powerful and more idiomatic to use in Kotlin. Following the signatures and naming of some other well-known APIs from Kotlin Std, or KotlinX Coroutines
Ior (API Size 65 -> 28)
(Bi)Functor / Applicative / Monad (API Size 22 -> 5)
Keep
Ior
Iors
.Right
orBoth
Remove
fold({ false }, predicate)
//map(predicate).getOrElse { false }
Left
,Right
, andBoth
{ it.map(f) }
{ it.map(fb).mapLeft(fa) }
map(fb).mapLeft(fa)
getOrNull()?.takeIf(predicate)
map { }
zip
will beinline ior
+bind
Applicative/MonadError (API Size 4 -> 4)
Keep
Right
value ifRight
orBoth
. Get default ifLeft
Left
orBoth
Foldable / (Bi)Traverse (API Size 25 -> 1)
Keep
Remove
All traverse, bitraverse, sequence, bisequence, crosswalk are set to be replace with
fold
fold
fold
fold
fold
Utilities (14 -> 9)
Keep
Both
from aPair
Right
ifIor
isRight
orBoth
.Left
ifIor
isLeft
orBoth
.Left
from a valuePair
o nullables.Right
from a valueRight
if theIor
isRight
orBoth
.Left
otherwise.Either
of theIor
Remove
isLeft
isRight