Skip to content

AsyncResult helps model asynchronous operations, and provides an ecosystem of operands on top of it

License

Notifications You must be signed in to change notification settings

mrmans0n/asyncresult

Repository files navigation

AsyncResult - Results for async operations in Kotlin Multiplatform

Build & test AsyncResult

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 yet
  • Loading - The operation is in progress
  • Success - The operation completed successfully with a value
  • Error - The operation failed, optionally with a throwable and metadata

The 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.

Modules

asyncresult (Core)

The core module contains the type hierarchy and all essential utilities:

  • Transformations - mapSuccess, mapError, flatMap, bimap, fold, orError, filterOrError, castOrError
  • Value extraction - getOrNull, getOrDefault, getOrElse, getOrThrow, getOrEmpty
  • Side effects - onSuccess, onLoading, onError, onNotStarted
  • Unwrapping - unwrap, unwrapError, expect, expectError (Rust-style extraction)
  • Combining - zip, zipWith, and, andThen, spread, combine, sequence
  • Recovery - recover, recoverIf, or, orElse
  • Validation - toErrorIf, toErrorUnless
  • Flow helpers - asAsyncResult, onLoading, onSuccess, onError, skipWhileLoading, cacheLatestSuccess, timeoutToError, retryOnError
  • Collection utilities - getAllErrors, anyLoading, anyIncomplete

asyncresult-either

Extensions for interoperability with Arrow's Either type:

  • Conversion - toAsyncResult() to convert Either to AsyncResult
  • Binding - bind() to flatten AsyncResult<Either<L, R>> to AsyncResult<R>
  • Flow conversion - asAsyncResult() to convert Flow<Either<L, R>> to Flow<AsyncResult<R>>, toEither() to convert Flow<AsyncResult<T>> to Either

asyncresult-test

Testing utilities built on assertk:

  • State assertions - isNotStarted(), isLoading(), isIncomplete(), isSuccess(), isError()
  • Value assertions - isSuccessEqualTo(), isErrorWithMetadata(), isErrorWithMetadataEqualTo()
  • Flow assertions - assertSuccess(), assertError() for testing flow emissions

Usage

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>")
}

Documentation

📚 mrmans0n.github.io/asyncresult

License

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.

About

AsyncResult helps model asynchronous operations, and provides an ecosystem of operands on top of it

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages