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

Commit

Permalink
Implement Either#merge() (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
m50d committed Nov 11, 2020
1 parent faad2fb commit b81b518
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions arrow-core-data/src/main/kotlin/arrow/core/Either.kt
Expand Up @@ -1183,6 +1183,18 @@ inline fun <A, B> EitherOf<A, B>.filterOrOther(predicate: (B) -> Boolean, defaul
else Left(default(it))
}

/**
* Returns the value from this [Either.Right] or [Either.Left].
*
* Example:
* ```
* Right(12).merge() // Result: 12
* Left(12).merge() // Result: 12
* ```
*/
inline fun <A> EitherOf<A, A>.merge(): A =
fix().fold(::identity, ::identity)

/**
* Returns [Either.Right] with the existing value of [Either.Right] if this is an [Either.Right] with a non-null value.
* The returned Either.Right type is not nullable.
Expand Down

0 comments on commit b81b518

Please sign in to comment.