Fix mis-ordered modifier keywords
https://kotlinlang.org/docs/reference/coding-conventions.html#modifiers
This commit is contained in:
parent
de239962da
commit
631f81d8ae
@ -10,7 +10,7 @@ infix fun <V, E> Result<V, E>.and(result: Result<V, E>): Result<V, E> {
|
|||||||
*
|
*
|
||||||
* - Rust: [Result.and](https://doc.rust-lang.org/std/result/enum.Result.html#method.and)
|
* - Rust: [Result.and](https://doc.rust-lang.org/std/result/enum.Result.html#method.and)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.and(result: () -> Result<V, E>): Result<V, E> {
|
inline infix fun <V, E> Result<V, E>.and(result: () -> Result<V, E>): Result<V, E> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> result()
|
is Ok -> result()
|
||||||
is Err -> this
|
is Err -> this
|
||||||
@ -24,7 +24,7 @@ infix inline fun <V, E> Result<V, E>.and(result: () -> Result<V, E>): Result<V,
|
|||||||
* - Elm: [Result.andThen](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#andThen)
|
* - Elm: [Result.andThen](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#andThen)
|
||||||
* - Rust: [Result.and_then](https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then)
|
* - Rust: [Result.and_then](https://doc.rust-lang.org/std/result/enum.Result.html#method.and_then)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E, U> Result<V, E>.andThen(transform: (V) -> Result<U, E>): Result<U, E> {
|
inline infix fun <V, E, U> Result<V, E>.andThen(transform: (V) -> Result<U, E>): Result<U, E> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> transform(value)
|
is Ok -> transform(value)
|
||||||
is Err -> this
|
is Err -> this
|
||||||
|
@ -40,7 +40,7 @@ infix fun <V, E> Result<V, E>.getOr(default: V): V {
|
|||||||
* @param default The value to return if [Err].
|
* @param default The value to return if [Err].
|
||||||
* @return The [value][Ok.value] if [Ok], otherwise [default].
|
* @return The [value][Ok.value] if [Ok], otherwise [default].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.getOr(default: () -> V): V {
|
inline infix fun <V, E> Result<V, E>.getOr(default: () -> V): V {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> value
|
is Ok -> value
|
||||||
is Err -> default()
|
is Err -> default()
|
||||||
@ -60,7 +60,7 @@ infix fun <V, E> Result<V, E>.getErrorOr(default: E): E {
|
|||||||
* @param default The error to return if [Ok].
|
* @param default The error to return if [Ok].
|
||||||
* @return The [error][Err.error] if [Err], otherwise [default].
|
* @return The [error][Err.error] if [Err], otherwise [default].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.getErrorOr(default: () -> E): E {
|
inline infix fun <V, E> Result<V, E>.getErrorOr(default: () -> E): E {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> default()
|
is Ok -> default()
|
||||||
is Err -> error
|
is Err -> error
|
||||||
@ -74,7 +74,7 @@ infix inline fun <V, E> Result<V, E>.getErrorOr(default: () -> E): E {
|
|||||||
* - Elm: [Result.extract](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#extract)
|
* - Elm: [Result.extract](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#extract)
|
||||||
* - Rust: [Result.unwrap_or_else](https://doc.rust-lang.org/src/core/result.rs.html#735-740)
|
* - Rust: [Result.unwrap_or_else](https://doc.rust-lang.org/src/core/result.rs.html#735-740)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.getOrElse(transform: (E) -> V): V {
|
inline infix fun <V, E> Result<V, E>.getOrElse(transform: (E) -> V): V {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> value
|
is Ok -> value
|
||||||
is Err -> transform(error)
|
is Err -> transform(error)
|
||||||
@ -85,7 +85,7 @@ infix inline fun <V, E> Result<V, E>.getOrElse(transform: (E) -> V): V {
|
|||||||
* Returns the [error][Err.error] if this [Result] is [Err], otherwise
|
* Returns the [error][Err.error] if this [Result] is [Err], otherwise
|
||||||
* the [transformation][transform] of the [value][Ok.value].
|
* the [transformation][transform] of the [value][Ok.value].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.getErrorOrElse(transform: (V) -> E): E {
|
inline infix fun <V, E> Result<V, E>.getErrorOrElse(transform: (V) -> E): E {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> transform(value)
|
is Ok -> transform(value)
|
||||||
is Err -> error
|
is Err -> error
|
||||||
|
@ -8,7 +8,7 @@ package com.github.michaelbull.result
|
|||||||
* - Haskell: [Data.Bifunctor.first](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:first)
|
* - Haskell: [Data.Bifunctor.first](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:first)
|
||||||
* - Rust: [Result.map](https://doc.rust-lang.org/std/result/enum.Result.html#method.map)
|
* - Rust: [Result.map](https://doc.rust-lang.org/std/result/enum.Result.html#method.map)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E> {
|
inline infix fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> Ok(transform(value))
|
is Ok -> Ok(transform(value))
|
||||||
is Err -> this
|
is Err -> this
|
||||||
@ -23,7 +23,7 @@ infix inline fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E> {
|
|||||||
* - Haskell: [Data.Bifunctor.right](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:second)
|
* - Haskell: [Data.Bifunctor.right](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:second)
|
||||||
* - Rust: [Result.map_err](https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err)
|
* - Rust: [Result.map_err](https://doc.rust-lang.org/std/result/enum.Result.html#method.map_err)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E, F> Result<V, E>.mapError(transform: (E) -> F): Result<V, F> {
|
inline infix fun <V, E, F> Result<V, E>.mapError(transform: (E) -> F): Result<V, F> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> this
|
is Ok -> this
|
||||||
is Err -> Err(transform(error))
|
is Err -> Err(transform(error))
|
||||||
@ -73,6 +73,6 @@ inline fun <V, E, U, F> Result<V, E>.mapEither(
|
|||||||
*
|
*
|
||||||
* - Scala: [Either.flatMap](http://www.scala-lang.org/api/2.12.0/scala/util/Either.html#flatMap[AA>:A,Y](f:B=>scala.util.Either[AA,Y]):scala.util.Either[AA,Y])
|
* - Scala: [Either.flatMap](http://www.scala-lang.org/api/2.12.0/scala/util/Either.html#flatMap[AA>:A,Y](f:B=>scala.util.Either[AA,Y]):scala.util.Either[AA,Y])
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E, U> Result<V, E>.flatMap(transform: (V) -> Result<U, E>): Result<U, E> {
|
inline infix fun <V, E, U> Result<V, E>.flatMap(transform: (V) -> Result<U, E>): Result<U, E> {
|
||||||
return andThen(transform)
|
return andThen(transform)
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ package com.github.michaelbull.result
|
|||||||
/**
|
/**
|
||||||
* Invokes a [callback] if this [Result] is [Ok].
|
* Invokes a [callback] if this [Result] is [Ok].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.onSuccess(callback: (V) -> Unit) = mapBoth(callback, {})
|
inline infix fun <V, E> Result<V, E>.onSuccess(callback: (V) -> Unit) = mapBoth(callback, {})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes a [callback] if this [Result] is [Err].
|
* Invokes a [callback] if this [Result] is [Err].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.onFailure(callback: (E) -> Unit) = mapBoth({}, callback)
|
inline infix fun <V, E> Result<V, E>.onFailure(callback: (E) -> Unit) = mapBoth({}, callback)
|
||||||
|
@ -10,7 +10,7 @@ infix fun <V, E> Result<V, E>.or(result: Result<V, E>): Result<V, E> {
|
|||||||
*
|
*
|
||||||
* - Rust: [Result.or](https://doc.rust-lang.org/std/result/enum.Result.html#method.or)
|
* - Rust: [Result.or](https://doc.rust-lang.org/std/result/enum.Result.html#method.or)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E> {
|
inline infix fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> this
|
is Ok -> this
|
||||||
is Err -> result()
|
is Err -> result()
|
||||||
@ -23,7 +23,7 @@ infix inline fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E
|
|||||||
*
|
*
|
||||||
* - Rust: [Result.or_else](https://doc.rust-lang.org/std/result/enum.Result.html#method.or_else)
|
* - Rust: [Result.or_else](https://doc.rust-lang.org/std/result/enum.Result.html#method.or_else)
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.orElse(transform: (E) -> Result<V, E>): Result<V, E> {
|
inline infix fun <V, E> Result<V, E>.orElse(transform: (E) -> Result<V, E>): Result<V, E> {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> this
|
is Ok -> this
|
||||||
is Err -> transform(error)
|
is Err -> transform(error)
|
||||||
|
@ -29,7 +29,7 @@ infix fun <V, E> Result<V, E>.expect(message: String): V {
|
|||||||
* @param message The message to include in the [UnwrapException] if the [Result] is an [Err].
|
* @param message The message to include in the [UnwrapException] if the [Result] is an [Err].
|
||||||
* @throws UnwrapException if the [Result] is an [Err], with the specified [message].
|
* @throws UnwrapException if the [Result] is an [Err], with the specified [message].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.expect(message: () -> Any): V {
|
inline infix fun <V, E> Result<V, E>.expect(message: () -> Any): V {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> value
|
is Ok -> value
|
||||||
is Err -> throw UnwrapException("${message()} $error")
|
is Err -> throw UnwrapException("${message()} $error")
|
||||||
@ -63,7 +63,7 @@ infix fun <V, E> Result<V, E>.expectError(message: String): E {
|
|||||||
* @param message The message to include in the [UnwrapException] if the [Result] is [Ok].
|
* @param message The message to include in the [UnwrapException] if the [Result] is [Ok].
|
||||||
* @throws UnwrapException if the [Result] is [Ok], with the specified [message].
|
* @throws UnwrapException if the [Result] is [Ok], with the specified [message].
|
||||||
*/
|
*/
|
||||||
infix inline fun <V, E> Result<V, E>.expectError(message: () -> Any): E {
|
inline infix fun <V, E> Result<V, E>.expectError(message: () -> Any): E {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Ok -> throw UnwrapException("${message()} $value")
|
is Ok -> throw UnwrapException("${message()} $value")
|
||||||
is Err -> error
|
is Err -> error
|
||||||
|
Loading…
Reference in New Issue
Block a user