Skip to content

Added leftIfNull to Either.#972

Merged
pakoito merged 3 commits into
arrow-kt:masterfrom
atomcat1978:master
Aug 2, 2018
Merged

Added leftIfNull to Either.#972
pakoito merged 3 commits into
arrow-kt:masterfrom
atomcat1978:master

Conversation

@atomcat1978
Copy link
Copy Markdown
Contributor

No description provided.

* ```
*/
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) })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use flatMap instead of fold here to prevent recreating the left side!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true.

@pakoito
Copy link
Copy Markdown
Member

pakoito commented Aug 2, 2018

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
Copy link
Copy Markdown

codecov Bot commented Aug 2, 2018

Codecov Report

Merging #972 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...re/arrow-core/src/main/kotlin/arrow/core/Either.kt 47.69% <0%> (-0.75%) 8 <0> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a949054...2da44b9. Read the comment docs.

@atomcat1978 atomcat1978 force-pushed the master branch 2 times, most recently from c8c747e to 1d0ec30 Compare August 2, 2018 12:08
Copy link
Copy Markdown
Member

@pakoito pakoito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready to merge!

@atomcat1978
Copy link
Copy Markdown
Contributor Author

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) }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised our linter doesn't complain about the extra whitespace here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U mean at the beginning. Yes, IntelliJ has added some extra here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Before it == null as well.

@pakoito pakoito merged commit 630fa7e into arrow-kt:master Aug 2, 2018
@pakoito
Copy link
Copy Markdown
Member

pakoito commented Aug 2, 2018

Aaaaand merged. Thanks @atomcat1978 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants