option-t
Version:
A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.
19 lines (18 loc) • 550 B
JavaScript
import { isNone, unwrapSome } from './option.js';
/**
* Returns `None` if the _input_ is `None`,
* otherwise calls _transformer_ with the value and returns the result.
*
* XXX:
* Some languages call this operation flatmap.
* But we don't provide `flatMap()` as alias of this function
* to sort with other APIs.
*/
export async function andThenAsyncForOption(input, transformer) {
if (isNone(input)) {
return input;
}
const inner = unwrapSome(input);
const result = await transformer(inner);
return result;
}