
Asynchronous operation state modeled as NotStarted, Loading, Success, Error with functional-style extensions, Either interop and testing helpers for concise, explicit handling of load/error flows.
AsyncResult is a small Kotlin Multiplatform library to model asynchronous operations using a sealed hierarchy. It captures the common states you deal with in UI and data layers:
NotStarted - The operation hasn't begun yetLoading - The operation is in progressSuccess - The operation completed successfully with a valueError - The operation failed, optionally with a throwable, metadata, and error IDThe library provides a rich set of operators for transforming, combining, and extracting values from these states, making it easy to handle async operations in a type-safe way.
The core module contains the type hierarchy and all essential utilities:
mapSuccess, mapError, flatMap, flatten, bimap, fold, orError, filterOrError, castOrError
isSuccess, isError, isIncomplete, isSuccessAnd, isErrorAnd, isErrorWithMetadataAnd, contains
getOrNull, getOrDefault, getOrElse, getOrThrow, getOrEmpty, errorOrNull, errorWithMetadataOrNull, throwableOrNull, errorIdOrNull
onSuccess, onLoading, onError, onErrorWithMetadata, onNotStarted, onIncomplete
unwrap, unwrapError, unwrapThrowable, unwrapMetadata, unwrapErrorId, expect, expectError, expectThrowable, expectMetadata, expectErrorId (Rust-style extraction)zip, zipWith, and, andThen, spread, combine, sequence
recover, recoverIf, or, orElse
toErrorIf, toErrorUnless
result { } comprehension with bind(), error(), loading(), ensure(), ensureNotNull()
asAsyncResult, onLoading, onSuccess, onError, onIncomplete, skipWhileLoading, filterNotLoading, cacheLatestSuccess, timeoutToError, retryOnError, retryOnErrorWithMetadata
errors, successes, throwables, incompletes, metadata, anyLoading, anyIncomplete, anyError, errorsFrom, partition
Extensions for interoperability with Arrow's Either type:
toAsyncResult() to convert Either to AsyncResult
bind() to flatten AsyncResult<Either<L, R>> to AsyncResult<R>
asAsyncResult() to convert Flow<Either<L, R>> to Flow<AsyncResult<R>>, toEither() to convert Flow<AsyncResult<T>> to Either
Raise<Error>.bind() to use AsyncResult inside Arrow's either { } / result { } blocksTesting utilities built on assertk:
isNotStarted(), isLoading(), isIncomplete(), isSuccess(), isError()
isSuccessEqualTo(), isErrorWithMetadata(), isErrorWithMetadataEqualTo()
isErrorWithThrowable(), isErrorWithThrowableOfType(), isErrorWithThrowableMessage(), isErrorWithId(), isErrorWithIdEqualTo(), hasErrorId()
assertSuccess(), assertError(), assertErrorWithMetadata(), assertErrorWithId(), assertFirstIsLoading(), assertFirstIsNotStarted(), assertFirstIsIncomplete()
hasAnyLoading(), hasAnyIncomplete(), allErrors(), allErrorMetadata()
dependencies {
implementation("io.nlopez.asyncresult:asyncresult:<version>")
// Optional: Arrow Either interop
implementation("io.nlopez.asyncresult:asyncresult-either:<version>")
// Optional: Testing helpers
testImplementation("io.nlopez.asyncresult:asyncresult-test:<version>")
}📚 mrmans0n.github.io/asyncresult
MIT License
Copyright (c) 2026 Nacho Lopez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
AsyncResult is a small Kotlin Multiplatform library to model asynchronous operations using a sealed hierarchy. It captures the common states you deal with in UI and data layers:
NotStarted - The operation hasn't begun yetLoading - The operation is in progressSuccess - The operation completed successfully with a valueError - The operation failed, optionally with a throwable, metadata, and error IDThe library provides a rich set of operators for transforming, combining, and extracting values from these states, making it easy to handle async operations in a type-safe way.
The core module contains the type hierarchy and all essential utilities:
mapSuccess, mapError, flatMap, flatten, bimap, fold, orError, filterOrError, castOrError
isSuccess, isError, isIncomplete, isSuccessAnd, isErrorAnd, isErrorWithMetadataAnd, contains
getOrNull, getOrDefault, getOrElse, getOrThrow, getOrEmpty, errorOrNull, errorWithMetadataOrNull, throwableOrNull, errorIdOrNull
onSuccess, onLoading, onError, onErrorWithMetadata, onNotStarted, onIncomplete
unwrap, unwrapError, unwrapThrowable, unwrapMetadata, unwrapErrorId, expect, expectError, expectThrowable, expectMetadata, expectErrorId (Rust-style extraction)zip, zipWith, and, andThen, spread, combine, sequence
recover, recoverIf, or, orElse
toErrorIf, toErrorUnless
result { } comprehension with bind(), error(), loading(), ensure(), ensureNotNull()
asAsyncResult, onLoading, onSuccess, onError, onIncomplete, skipWhileLoading, filterNotLoading, cacheLatestSuccess, timeoutToError, retryOnError, retryOnErrorWithMetadata
errors, successes, throwables, incompletes, metadata, anyLoading, anyIncomplete, anyError, errorsFrom, partition
Extensions for interoperability with Arrow's Either type:
toAsyncResult() to convert Either to AsyncResult
bind() to flatten AsyncResult<Either<L, R>> to AsyncResult<R>
asAsyncResult() to convert Flow<Either<L, R>> to Flow<AsyncResult<R>>, toEither() to convert Flow<AsyncResult<T>> to Either
Raise<Error>.bind() to use AsyncResult inside Arrow's either { } / result { } blocksTesting utilities built on assertk:
isNotStarted(), isLoading(), isIncomplete(), isSuccess(), isError()
isSuccessEqualTo(), isErrorWithMetadata(), isErrorWithMetadataEqualTo()
isErrorWithThrowable(), isErrorWithThrowableOfType(), isErrorWithThrowableMessage(), isErrorWithId(), isErrorWithIdEqualTo(), hasErrorId()
assertSuccess(), assertError(), assertErrorWithMetadata(), assertErrorWithId(), assertFirstIsLoading(), assertFirstIsNotStarted(), assertFirstIsIncomplete()
hasAnyLoading(), hasAnyIncomplete(), allErrors(), allErrorMetadata()
dependencies {
implementation("io.nlopez.asyncresult:asyncresult:<version>")
// Optional: Arrow Either interop
implementation("io.nlopez.asyncresult:asyncresult-either:<version>")
// Optional: Testing helpers
testImplementation("io.nlopez.asyncresult:asyncresult-test:<version>")
}📚 mrmans0n.github.io/asyncresult
MIT License
Copyright (c) 2026 Nacho Lopez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.