UNPKG

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

29 lines (28 loc) 1.24 kB
import type { EffectFn } from '../../../internal/function.js'; import type { Mutable } from '../../../internal/mutable.js'; import { type Option, type Some } from '../option.js'; export type MutSome<out T> = Mutable<Some<T>>; export type UnsafeSomeDestructorFn<in T> = EffectFn<MutSome<T>>; /** * The _mutator_ is called if _input_ is `Some<T>`. * * This function allows you to cut the reference to the contain value from the inputted _input_. * However, it would be unsafe operation if you do some more operation after this. * For example, you can write the following code. * * ```javascript * const some = createSome(1); * unsafeDropForOption(some, (some) => { * some.ok = false; * }); * isSome(some); // -> false. This is dangerous. * ``` * * Compared to Rust, JavaScript does not have ownership semantics in language * and this API is designed to use as a destructor or similar fashions. * So if you call this for same object more than once, your code might contain "double free" problem. * * @throws * This throw an `Error` instance if the _input_ is frozen. */ export declare function unsafeDropForOption<T>(input: Option<T>, mutator: UnsafeSomeDestructorFn<T>): void;