AsyncRepositoryReturn<T> is the asynchronous counterpart of RepositoryReturn<T>.
It models repository-like async operations where:
- absence of data is meaningful
- errors are explicit
- results may contain multiple values
AsyncRepositoryReturn<T>
≈ Promise<RepositoryReturn<T>>
≈ Promise<Either<Error, Maybe<Array<T>>>>Using Promise<T | null> or throwing exceptions conflates:
- transport errors
- absence of data
- empty collections
AsyncRepositoryReturn keeps these concerns orthogonal and composable.
ARR.success(value)
ARR.failure(error)
ARR.none()
ARR.create(value)
ARR.fromPromise(promise)
ARR.fromResult(result)await arr.isSuccess()
await arr.isFailure()
await arr.isNone()arr.match(
onNone,
onFailure,
onSuccess
)Each branch:
- may return values, RepositoryReturn, or Promises
- exceptions are captured as failures
arr.map(fn)
arr.mapSuccess(fn)
arr.mapElements(fn)
arr.mapFirst(fn)arr.mapFailure(fn)
arr.mapNone(fn)arr.noneAsFailure(err)
arr.noneAsSuccess(values)
arr.failureAsNone()arr.then(fn)
arr._then(fn)Behaves like Promise.then, but:
- preserves semantic structure
- never loses error / none distinction
await arr.asResult(fallback)
await arr.asFirstElementResult(fallback)await arr.toPromise()
await arr.valuearr.catch(err => ...)Errors become structured failures, not thrown exceptions.
- Referential transparency
- Exception safety
- Explicit absence
- Total pattern matching
- Async-safe monadic composition
RepositoryReturn describes “what happened” AsyncRepositoryReturn describes “what will happen”