Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/ahh/src/option.ts>map

Opinionated idiomatic features for TypeScript.
Go to Latest
function map
import { map } from "https://deno.land/x/ahh@v0.12.1/src/option.ts";

Returns option with its value mapped via fn, if it is a Some.

Examples

Example 1

import { default as O, Option } from "./option.ts";

const num: Option<number> = 8;
const double = O.map(num, (i) => i * 2);

if (O.isSome(double)) {
  console.log(num, "doubled is", double);
}

Parameters

option: Option<T>
fn: (_: T) => Option<U> | U

Returns

Option<U>