method Result.prototype.map
Result.prototype.map<U>(fn: (value: T) => U): Result<U, E>

Transforms the Ok value using a mapper function, leaving Err untouched.

Examples

Example 1

const result = Result.ok(5)
  .map(x => x * 2)
  .map(x => x.toString());

const value = result.take();
if (!isErr(value)) {
  console.log(value); // "10"
}

Type Parameters

The type of the transformed value

Parameters

fn: (value: T) => U

Function to transform the Ok value

Return Type

A new Result with the transformed value, or the original Err

Usage

import { Result } from "result/mod.ts";