Skip to main content
Module

x/optio/mod.ts>map

Minimum option type port of Rust
Latest
function map
import { map } from "https://deno.land/x/optio@1.0.0/mod.ts";

Maps an Option<T> to Option<U> by applying a function to a contained value(if Some) or returns None(if None).

Examples

Example 1

import { map, Option, Some } from "https://deno.land/x/optio/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

const option: Option<string> = Some("Hello, World!");
const optionLen = map(option, (v) => v.length);

assertEquals(optionLen, Some(13));

Parameters

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