Use filterIsInstance in getAll methods

This commit is contained in:
Michael Bull 2017-10-22 15:24:37 +01:00
parent 7be628e79e
commit 1933c9f845
2 changed files with 3 additions and 3 deletions

View File

@ -1,5 +1,5 @@
group=com.github.michaelbull.kotlin-result
version=1.0.1-SNAPSHOT
version=1.1.1-SNAPSHOT
dokkaVersion=0.9.15
gradleReleaseVersion=2.6.0

View File

@ -103,7 +103,7 @@ fun <V, E> getAll(vararg results: Result<V, E>) = results.asIterable().getAll()
* @return The extracted [Ok] elements.
*/
fun <V, E> Iterable<Result<V, E>>.getAll(): List<V> {
return filter { it is Ok }.map { (it as Ok).value }
return filterIsInstance<Ok<V>>().map { it.value }
}
/**
@ -126,7 +126,7 @@ fun <V, E> getAllErrors(vararg results: Result<V, E>) = results.asIterable().get
* @return The extracted [Error] elements.
*/
fun <V, E> Iterable<Result<V, E>>.getAllErrors(): List<E> {
return filter { it is Error }.map { (it as Error).error }
return filterIsInstance<Error<E>>().map { it.error }
}
/**