For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/functions/Option.map.md.

Function: map()

Applies a transformation function to the value of an Option or OptionAsync. If the input is a None, it is returned unchanged.

Type Param

O

The input Option or OptionAsync.

Type Param

U

The transformed value type.

Examples

Some Case

import { 
import Option
Option
} from 'byenull';
const
const option: Option.Option<number>
option
=
import Option
Option
.
function pipe<Option.Option<number>, Option.Option<number>>(a: Option.Option<number>, ab: (a: Option.Option<number>) => Option.Option<number>): Option.Option<number> (+25 overloads)

Applies a sequence of functions to a value, from left to right.

This utility enables function composition in a left-to-right manner. It supports up to 25 chained functions from A through Z.

@typeParamA - The initial input value type.@typeParamB-Z - Intermediate and final function return types.@paramvalue - The initial input value.@paramfunctions - Additional unary functions composing of the previous result.@returnsThe final result after applying all functions.@example
import { Option } from 'byenull';

const result = Option.pipe(
  2,
  x => x + 1,
  x => x * 3,
  x => `Result: ${x}`
);
// Result: 9
@categoryUtilities
pipe
(
import Option
Option
.
function some<number>(value: number): Option.Option<number>

Creates a Some from a given value. Passing null or undefined returns None instead.

@typeParamT - The type of the value to wrap.@returnsA Some containing the value, or None if the value is nullish.@example
import { Option } from 'byenull';

const some = Option.some(42);
// { type: 'Some', value: 42 }

const none = Option.some(null);
// { type: 'None' }
@categoryCreators
some
(2),
import Option
Option
.
function map<Option.Option<number>, number>(fn: (a: number) => number): (option: Option.Option<number>) => Option.Option<number> (+1 overload)

Applies a transformation function to the value of an Option or OptionAsync . If the input is a None , it is returned unchanged.

@typeParamO - The input Option or OptionAsync.@typeParamU - The transformed value type.@example

Some Case

import { Option } from 'byenull';

const option = Option.pipe(
Option.some(2),
Option.map((x) => x * 10),
);
// { type: 'Some', value: 20 }
@example

None Case (unchanged)

import { Option } from 'byenull';

const option = Option.pipe(
Option.none(),
Option.map((x: number) => x * 10),
);
// { type: 'None' }
@seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
map
((
x: number
x
) =>
x: number
x
* 10),
); // { type: 'Some', value: 20 }

None Case (unchanged)

import { 
import Option
Option
} from 'byenull';
const
const option: Option.Option<number>
option
=
import Option
Option
.
function pipe<Option.Option<never>, Option.Option<number>>(a: Option.Option<never>, ab: (a: Option.Option<never>) => Option.Option<number>): Option.Option<number> (+25 overloads)

Applies a sequence of functions to a value, from left to right.

This utility enables function composition in a left-to-right manner. It supports up to 25 chained functions from A through Z.

@typeParamA - The initial input value type.@typeParamB-Z - Intermediate and final function return types.@paramvalue - The initial input value.@paramfunctions - Additional unary functions composing of the previous result.@returnsThe final result after applying all functions.@example
import { Option } from 'byenull';

const result = Option.pipe(
  2,
  x => x + 1,
  x => x * 3,
  x => `Result: ${x}`
);
// Result: 9
@categoryUtilities
pipe
(
import Option
Option
.
function none(): Option.Option<never>

Creates a None : an Option that holds no value.

@returnsA None.@example
import { Option } from 'byenull';

const option = Option.none();
// { type: 'None' }
@categoryCreators
none
(),
import Option
Option
.
function map<Option.Option<never>, number>(fn: (a: never) => number): (option: Option.Option<never>) => Option.Option<number> (+1 overload)

Applies a transformation function to the value of an Option or OptionAsync . If the input is a None , it is returned unchanged.

@typeParamO - The input Option or OptionAsync.@typeParamU - The transformed value type.@example

Some Case

import { Option } from 'byenull';

const option = Option.pipe(
Option.some(2),
Option.map((x) => x * 10),
);
// { type: 'Some', value: 20 }
@example

None Case (unchanged)

import { Option } from 'byenull';

const option = Option.pipe(
Option.none(),
Option.map((x: number) => x * 10),
);
// { type: 'None' }
@seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators
map
((
x: number
x
: number) =>
x: number
x
* 10),
); // { type: 'None' }

See

pipe - It is recommended to use this function with the pipe function for better readability and composability.

Call Signature

map<O, U>(fn): (option) => OptionFor<O, U>

Type Parameters

O

O extends OptionMaybeAsync<any>

U

U

Parameters

fn

(a) => U

Returns

(option) => OptionFor<O, U>

Call Signature

map<T, U>(fn): <O2>(option) => OptionFor<O2, U>

Type Parameters

T

T extends NonNullableValue

U

U extends NonNullableValue

Parameters

fn

(a) => U

Returns

<O2>(option) => OptionFor<O2, U>