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.
Latest
function map
import { map } from "https://deno.land/x/ahh@v0.14.0/src/option.ts";

Returns the result of fn appied to the value of option, if it is a Some.

Examples

Example 1

import { assert } from "../test_deps.ts";
import O from "./option.ts";

const toString = (i: number): string => i.toString();

assert(O.map(2, toString) === "2");
assert(O.map(undefined, toString) === undefined);
assert(O.map(null, toString) === null);

Type Parameters

T
U extends Some<unknown>

Parameters

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