Simplify doc comments according to Kotlin Coding Conventions

https://kotlinlang.org/docs/reference/coding-conventions.html#documentation-comments
This commit is contained in:
Michael Bull 2018-01-09 21:20:00 +00:00
parent c6be93142d
commit c5a11a914e
8 changed files with 10 additions and 85 deletions

View File

@ -9,9 +9,6 @@ infix fun <V, E> Result<V, E>.and(result: Result<V, E>): Result<V, E> {
* Returns [result] if this [Result] is [Ok], otherwise this [Err]. * Returns [result] if this [Result] is [Ok], otherwise this [Err].
* *
* - 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)
*
* @param result The [Result] to return if [Ok].
* @return The [result] if [Ok], otherwise [Err].
*/ */
infix inline fun <V, E> Result<V, E>.and(result: () -> Result<V, E>): Result<V, E> { infix inline fun <V, E> Result<V, E>.and(result: () -> Result<V, E>): Result<V, E> {
return when (this) { return when (this) {
@ -26,9 +23,6 @@ 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)
*
* @param transform The transformation to apply to the [value][Ok.value].
* @return The [transformed][transform] [Result] if [Ok], otherwise [Err].
*/ */
infix inline fun <V, E, U> Result<V, E>.andThen(transform: (V) -> Result<U, E>): Result<U, E> { infix inline fun <V, E, U> Result<V, E>.andThen(transform: (V) -> Result<U, E>): Result<U, E> {
return when (this) { return when (this) {

View File

@ -5,8 +5,6 @@ package com.github.michaelbull.result
* *
* - Elm: [Result.toMaybe](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#toMaybe) * - Elm: [Result.toMaybe](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#toMaybe)
* - Rust: [Result.ok](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok) * - Rust: [Result.ok](https://doc.rust-lang.org/std/result/enum.Result.html#method.ok)
*
* @return The [value][Ok.value] if [Ok], otherwise `null`.
*/ */
fun <V, E> Result<V, E>.get(): V? { fun <V, E> Result<V, E>.get(): V? {
return when (this) { return when (this) {
@ -19,8 +17,6 @@ fun <V, E> Result<V, E>.get(): V? {
* Returns the [error][Err.error] if this [Result] is [Err], otherwise `null`. * Returns the [error][Err.error] if this [Result] is [Err], otherwise `null`.
* *
* - Rust: [Result.err](https://doc.rust-lang.org/std/result/enum.Result.html#method.err) * - Rust: [Result.err](https://doc.rust-lang.org/std/result/enum.Result.html#method.err)
*
* @return The [error][Err.error] if [Err], otherwise `null`.
*/ */
fun <V, E> Result<V, E>.getError(): E? { fun <V, E> Result<V, E>.getError(): E? {
return when (this) { return when (this) {
@ -77,9 +73,6 @@ 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)
*
* @param transform The transformation to apply to the [error][Err.error].
* @return The [value][Ok.value] if [Ok], otherwise the [transformed][transform] [error][Err.error].
*/ */
infix inline fun <V, E> Result<V, E>.getOrElse(transform: (E) -> V): V { infix inline fun <V, E> Result<V, E>.getOrElse(transform: (E) -> V): V {
return when (this) { return when (this) {
@ -91,9 +84,6 @@ 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].
*
* @param transform The transformation to apply to the [value][Ok.value].
* @return The [error][Err.error] if [Err], otherwise the [transformed][transform] [value][Ok.value].
*/ */
infix inline fun <V, E> Result<V, E>.getErrorOrElse(transform: (V) -> E): E { infix inline fun <V, E> Result<V, E>.getErrorOrElse(transform: (V) -> E): E {
return when (this) { return when (this) {

View File

@ -1,11 +1,7 @@
package com.github.michaelbull.result package com.github.michaelbull.result
/** /**
* Accumulates value starting with [initial] value and applying [operation] from left to right to * Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
* current accumulator value and each element.
*
* @param initial The value to start with.
* @param operation The operation to apply to each element and current accumulator value.
*/ */
inline fun <T, R, E> Iterable<T>.fold( inline fun <T, R, E> Iterable<T>.fold(
initial: R, initial: R,
@ -28,11 +24,7 @@ inline fun <T, R, E> Iterable<T>.fold(
} }
/** /**
* Accumulates value starting with [initial] value and applying [operation] from right to left to * Accumulates value starting with [initial] value and applying [operation] from right to left to each element and current accumulator value.
* each element and current accumulator value.
*
* @param initial The value to start with.
* @param operation The operation to apply to each element and current accumulator value.
*/ */
inline fun <T, R, E> List<T>.foldRight( inline fun <T, R, E> List<T>.foldRight(
initial: R, initial: R,
@ -58,21 +50,16 @@ inline fun <T, R, E> List<T>.foldRight(
} }
/** /**
* Combine a vararg of [Results][Result] into a single [Result] (holding a [List]). * Combines a vararg of [Results][Result] into a single [Result] (holding a [List]).
* *
* - Elm: [Result.Extra.combine](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#combine) * - Elm: [Result.Extra.combine](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#combine)
*
* @param results The [Results][Result] to combine.
* @return The combined [Result].
*/ */
fun <V, E> combine(vararg results: Result<V, E>) = results.asIterable().combine() fun <V, E> combine(vararg results: Result<V, E>) = results.asIterable().combine()
/** /**
* Combine an [Iterable] of [Results][Result] into a single [Result] (holding a [List]). * Combines an [Iterable] of [Results][Result] into a single [Result] (holding a [List]).
* *
* - Elm: [Result.Extra.combine](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#combine) * - Elm: [Result.Extra.combine](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#combine)
*
* @return The combined [Result].
*/ */
fun <V, E> Iterable<Result<V, E>>.combine(): Result<List<V>, E> { fun <V, E> Iterable<Result<V, E>>.combine(): Result<List<V>, E> {
return Ok(map { return Ok(map {
@ -88,9 +75,6 @@ fun <V, E> Iterable<Result<V, E>>.combine(): Result<List<V>, E> {
* extracted in order. * extracted in order.
* *
* - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts) * - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts)
*
* @param results The [Results][Result] from which to extract [Ok] elements.
* @return The extracted [Ok] elements.
*/ */
fun <V, E> getAll(vararg results: Result<V, E>) = results.asIterable().getAll() fun <V, E> getAll(vararg results: Result<V, E>) = results.asIterable().getAll()
@ -99,8 +83,6 @@ fun <V, E> getAll(vararg results: Result<V, E>) = results.asIterable().getAll()
* are extracted in order. * are extracted in order.
* *
* - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts) * - Haskell: [Data.Either.lefts](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:lefts)
*
* @return The extracted [Ok] elements.
*/ */
fun <V, E> Iterable<Result<V, E>>.getAll(): List<V> { fun <V, E> Iterable<Result<V, E>>.getAll(): List<V> {
return filterIsInstance<Ok<V>>().map { it.value } return filterIsInstance<Ok<V>>().map { it.value }
@ -111,9 +93,6 @@ fun <V, E> Iterable<Result<V, E>>.getAll(): List<V> {
* are extracted in order. * are extracted in order.
* *
* - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights) * - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights)
*
* @param results The [Results][Result] from which to extract [Err] elements.
* @return The extracted [Err] elements.
*/ */
fun <V, E> getAllErrors(vararg results: Result<V, E>) = results.asIterable().getAllErrors() fun <V, E> getAllErrors(vararg results: Result<V, E>) = results.asIterable().getAllErrors()
@ -122,8 +101,6 @@ fun <V, E> getAllErrors(vararg results: Result<V, E>) = results.asIterable().get
* elements are extracted in order. * elements are extracted in order.
* *
* - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights) * - Haskell: [Data.Either.rights](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:rights)
*
* @return The extracted [Err] elements.
*/ */
fun <V, E> Iterable<Result<V, E>>.getAllErrors(): List<E> { fun <V, E> Iterable<Result<V, E>>.getAllErrors(): List<E> {
return filterIsInstance<Err<E>>().map { it.error } return filterIsInstance<Err<E>>().map { it.error }
@ -135,10 +112,6 @@ fun <V, E> Iterable<Result<V, E>>.getAllErrors(): List<E> {
* extracted to the [Pair.second] value. * extracted to the [Pair.second] value.
* *
* - Haskell: [Data.Either.partitionEithers](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:partitionEithers) * - Haskell: [Data.Either.partitionEithers](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:partitionEithers)
*
* @param results The [Results][Result] to partition.
* @return A [Pair] of [Lists][List] where the [first][Pair.first] value
* contains the [Ok] elements and the [second][Pair.second] value contains the [Err] elements.
*/ */
fun <V, E> partition(vararg results: Result<V, E>) = results.asIterable().partition() fun <V, E> partition(vararg results: Result<V, E>) = results.asIterable().partition()
@ -148,9 +121,6 @@ fun <V, E> partition(vararg results: Result<V, E>) = results.asIterable().partit
* elements are extracted to the [Pair.second] value. * elements are extracted to the [Pair.second] value.
* *
* - Haskell: [Data.Either.partitionEithers](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:partitionEithers) * - Haskell: [Data.Either.partitionEithers](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:partitionEithers)
*
* @return A [Pair] of [Lists][List] where the [first][Pair.first] value
* contains the [Ok] elements and the [second][Pair.second] value contains the [Err] elements.
*/ */
fun <V, E> Iterable<Result<V, E>>.partition(): Pair<List<V>, List<E>> { fun <V, E> Iterable<Result<V, E>>.partition(): Pair<List<V>, List<E>> {
val values = mutableListOf<V>() val values = mutableListOf<V>()

View File

@ -7,9 +7,6 @@ package com.github.michaelbull.result
* - Elm: [Result.map](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#map) * - Elm: [Result.map](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#map)
* - 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)
*
* @param transform The transformation to apply to the [value][Ok.value]
* @return The [transformed][transform] [Result] if [Ok], otherwise [Err].
*/ */
infix inline fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E> { infix inline fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E> {
return when (this) { return when (this) {
@ -25,9 +22,6 @@ infix inline fun <V, E, U> Result<V, E>.map(transform: (V) -> U): Result<U, E> {
* - Elm: [Result.mapError](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#mapError) * - Elm: [Result.mapError](http://package.elm-lang.org/packages/elm-lang/core/latest/Result#mapError)
* - 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)
*
* @param transform The transformation to apply to the [error][Err.error].
* @return The [value][Ok.value] if [Ok], otherwise the [transformed][transform] [Err].
*/ */
infix inline fun <V, E, F> Result<V, E>.mapError(transform: (E) -> F): Result<V, F> { infix inline fun <V, E, F> Result<V, E>.mapError(transform: (E) -> F): Result<V, F> {
return when (this) { return when (this) {
@ -43,10 +37,6 @@ infix inline fun <V, E, F> Result<V, E>.mapError(transform: (E) -> F): Result<V,
* *
* - Elm: [Result.Extra.mapBoth](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#mapBoth) * - Elm: [Result.Extra.mapBoth](http://package.elm-lang.org/packages/circuithub/elm-result-extra/1.4.0/Result-Extra#mapBoth)
* - Haskell: [Data.Either.either](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:either) * - Haskell: [Data.Either.either](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Either.html#v:either)
*
* @param success The function to apply to `V` if [Ok].
* @param failure The function to apply to `E` if [Err].
* @return The mapped value.
*/ */
inline fun <V, E, U> Result<V, E>.mapBoth( inline fun <V, E, U> Result<V, E>.mapBoth(
success: (V) -> U, success: (V) -> U,
@ -64,10 +54,6 @@ inline fun <V, E, U> Result<V, E>.mapBoth(
* if this [Result] is [Ok], or the [failure] function if this [Result] is an [Err]. * if this [Result] is [Ok], or the [failure] function if this [Result] is an [Err].
* *
* - Haskell: [Data.Bifunctor.Bimap](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:bimap) * - Haskell: [Data.Bifunctor.Bimap](https://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Bifunctor.html#v:bimap)
*
* @param success The function to apply to `V` if [Ok].
* @param failure The function to apply to `E` if [Err].
* @return The mapped [Result].
*/ */
inline fun <V, E, U, F> Result<V, E>.mapEither( inline fun <V, E, U, F> Result<V, E>.mapEither(
success: (V) -> U, success: (V) -> U,
@ -86,9 +72,6 @@ inline fun <V, E, U, F> Result<V, E>.mapEither(
* This is functionally equivalent to [andThen]. * This is functionally equivalent to [andThen].
* *
* - 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])
*
* @param transform The transformation to apply to the [value][Ok.value].
* @return The [transformed][transform] [Result] if [Ok], otherwise [Err].
*/ */
infix inline fun <V, E, U> Result<V, E>.flatMap(transform: (V) -> Result<U, E>): Result<U, E> { infix inline fun <V, E, U> Result<V, E>.flatMap(transform: (V) -> Result<U, E>): Result<U, E> {
return andThen(transform) return andThen(transform)

View File

@ -2,12 +2,10 @@ package com.github.michaelbull.result
/** /**
* Invokes a [callback] if this [Result] is [Ok]. * Invokes a [callback] if this [Result] is [Ok].
* @param callback The function to call.
*/ */
infix inline fun <V, E> Result<V, E>.onSuccess(callback: (V) -> Unit) = mapBoth(callback, {}) infix inline 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].
* @param callback The function to call.
*/ */
infix inline fun <V, E> Result<V, E>.onFailure(callback: (E) -> Unit) = mapBoth({}, callback) infix inline fun <V, E> Result<V, E>.onFailure(callback: (E) -> Unit) = mapBoth({}, callback)

View File

@ -9,9 +9,6 @@ infix fun <V, E> Result<V, E>.or(result: Result<V, E>): Result<V, E> {
* Returns [result] if this [Result] is [Err], otherwise this [Ok]. * Returns [result] if this [Result] is [Err], otherwise this [Ok].
* *
* - 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)
*
* @param result The [Result] to return if [Err].
* @return The [result] if [Err], otherwise [Ok].
*/ */
infix inline fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E> { infix inline fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E> {
return when (this) { return when (this) {
@ -25,9 +22,6 @@ infix inline fun <V, E> Result<V, E>.or(result: () -> Result<V, E>): Result<V, E
* otherwise this [Ok]. * otherwise this [Ok].
* *
* - 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)
*
* @param transform The transformation to apply to the [error][Err.error].
* @return The [transformed][transform] [Result] if [Err], otherwise [Ok].
*/ */
infix inline fun <V, E> Result<V, E>.orElse(transform: (E) -> Result<V, E>): Result<V, E> { infix inline fun <V, E> Result<V, E>.orElse(transform: (E) -> Result<V, E>): Result<V, E> {
return when (this) { return when (this) {

View File

@ -27,9 +27,9 @@ sealed class Result<out V, out E> {
/** /**
* Represents a successful [Result], containing a [value]. * Represents a successful [Result], containing a [value].
*/ */
data class Ok<out V> constructor(val value: V) : Result<V, Nothing>() data class Ok<out V>(val value: V) : Result<V, Nothing>()
/** /**
* Represents a failed [Result], containing an [error] value. * Represents a failed [Result], containing an [error].
*/ */
data class Err<out E> constructor(val error: E) : Result<Nothing, E>() data class Err<out E>(val error: E) : Result<Nothing, E>()

View File

@ -1,24 +1,20 @@
package com.github.michaelbull.result package com.github.michaelbull.result
/** /**
* Creates an [Iterator] over the possibly contained [value][Ok.value]. * Returns an [Iterator] over the possibly contained [value][Ok.value].
* The iterator yields one [value][Ok.value] if the [Result] is [Ok], otherwise throws [NoSuchElementException]. * The iterator yields one [value][Ok.value] if the [Result] is [Ok], otherwise throws [NoSuchElementException].
* *
* - Rust: [Result.iter](https://doc.rust-lang.org/std/result/enum.Result.html#method.iter) * - Rust: [Result.iter](https://doc.rust-lang.org/std/result/enum.Result.html#method.iter)
*
* @return [Iterator] over the possibly contained [value][Ok.value].
*/ */
fun <V, E> Result<V, E>.iterator(): Iterator<V> { fun <V, E> Result<V, E>.iterator(): Iterator<V> {
return ResultIterator(this) return ResultIterator(this)
} }
/** /**
* Creates a [MutableIterator] over the possibly contained [value][Ok.value]. * Returns a [MutableIterator] over the possibly contained [value][Ok.value].
* The iterator yields one [value][Ok.value] if the [Result] is [Ok], otherwise throws [NoSuchElementException]. * The iterator yields one [value][Ok.value] if the [Result] is [Ok], otherwise throws [NoSuchElementException].
* *
* - Rust: [Result.iter_mut](https://doc.rust-lang.org/std/result/enum.Result.html#method.iter_mut) * - Rust: [Result.iter_mut](https://doc.rust-lang.org/std/result/enum.Result.html#method.iter_mut)
*
* @return The [MutableIterator] over the possibly contained [value][Ok.value].
*/ */
fun <V, E> Result<V, E>.mutableIterator(): MutableIterator<V> { fun <V, E> Result<V, E>.mutableIterator(): MutableIterator<V> {
return ResultIterator(this) return ResultIterator(this)
@ -46,7 +42,7 @@ private class ResultIterator<out V, out E>(private val result: Result<V, E>) : M
} }
/** /**
* @return The [Result's][Result] [value][Ok.value] if not [yielded] and [Ok]. * Returns the [Result's][Result] [value][Ok.value] if not [yielded] and [Ok].
* @throws NoSuchElementException if the [Result] is [yielded] or is not [Ok]. * @throws NoSuchElementException if the [Result] is [yielded] or is not [Ok].
*/ */
override fun next(): V { override fun next(): V {