Added leftIfNull to Either.#972
Conversation
| * ``` | ||
| */ | ||
| inline fun <A, B> EitherOf<A, B?>.leftIfNull(crossinline default: () -> A): Either<A, B> = | ||
| fix().fold({ Left(it) }, { if ( it == null) Left(default()) else Right(it) }) |
There was a problem hiding this comment.
Use flatMap instead of fold here to prevent recreating the left side!
|
One comment! And it'd be great if you added a snippet to the docs: https://github.com/arrow-kt/arrow/edit/master/modules/docs/arrow-docs/docs/docs/datatypes/either/README.md |
Codecov Report
@@ Coverage Diff @@
## master #972 +/- ##
============================================
- Coverage 46.67% 46.67% -0.01%
Complexity 649 649
============================================
Files 308 308
Lines 8008 8009 +1
Branches 820 821 +1
============================================
Hits 3738 3738
- Misses 3939 3940 +1
Partials 331 331
Continue to review full report at Codecov.
|
c8c747e to
1d0ec30
Compare
|
Perfect :) |
| * ``` | ||
| */ | ||
| inline fun <A, B> EitherOf<A, B?>.leftIfNull(crossinline default: () -> A): Either<A, B> = | ||
| fix().flatMap { if ( it == null) Left(default()) else Right(it) } |
There was a problem hiding this comment.
I'm surprised our linter doesn't complain about the extra whitespace here
There was a problem hiding this comment.
U mean at the beginning. Yes, IntelliJ has added some extra here.
There was a problem hiding this comment.
Fixed. Before it == null as well.
|
Aaaaand merged. Thanks @atomcat1978 !! |
No description provided.