Skip to content

LumaKernel/option-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

option-ts

Rust-like interface Option class.

Example

const v = Option.fromNullish(
  await fetchSomething(), /* which returns { something: number } | null */
);
const maybeSomething = v.map((e) => e.something);
const unwrapped = maybeSomething.unwrapOr(Number.NaN);

Is there .flatMap() method?

Use .andThen() instead.

How to work on async works only when the value is some?

We may want to something like following intuitively in Rust.

match v {
    Some(v) => {
        v.work.await;
    }
    _ => {}
}

But yes, that couldn't be possible even if using .match(). Instead you can do that as following.

await v.andThen(async (v) => await v.work()).awaited();

The method .awaited() converts from Option<Promise<T>> into Promise<Option<T>>.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published