#Function: inspect()
Executes a side effect function on the value of a Some in an Option or OptionAsync, without modifying the original option. This is useful for debugging, logging, or performing other side effects while maintaining the original value.
If the input is a None, the provided function is never called and the option is returned unchanged.
#Type Param
O
The input Option or OptionAsync.
#Type Param
R
The return type of the inspection function.
#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.@exampleimport { 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.@exampleimport { Option } from 'byenull';
const some = Option.some(42);
// { type: 'Some', value: 42 }
const none = Option.some(null);
// { type: 'None' }
@categoryCreators some (42),
import Option Option .function inspect<Option.Option<number>, void>(fn: (a: number) => void): (option: Option.Option<number>) => Option.Option<number> (+1 overload)Executes a side effect function on the value of a
Some
in an
Option
or
OptionAsync
,
without modifying the original option. This is useful for debugging, logging, or performing
other side effects while maintaining the original value.
If the input is a
None
, the provided function is never called and the option is returned unchanged.
@typeParamO - The input Option or OptionAsync.@typeParamR - The return type of the inspection function.@exampleSome Case
import { Option } from 'byenull';
const option = Option.pipe(
Option.some(42),
Option.inspect((value) => console.log('Debug:', value)),
);
// Console output: "Debug: 42"
// Option: { type: 'Some', value: 42 }
@exampleNone Case (fn is never called)
import { Option } from 'byenull';
const option = Option.pipe(
Option.none(),
Option.inspect((value: number) => console.log('Debug:', value)),
);
// No console output
// Option: { type: 'None' }
@exampleAsynchronous Side Effect
import { Option } from 'byenull';
const option = await Option.pipe(
Option.some(42),
Option.inspect(async (value) => {
await fetch(`/api/logs?value=${value}`);
}),
);
// { type: 'Some', value: 42 }
@seeinspectNone - For inspecting a None instead.@seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators inspect ((value: number value ) => var console: Console console .Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log ('Debug:', value: number value )),
);
// Console output: "Debug: 42"
// Option: { type: 'Some', value: 42 }None Case (fn is never called)
import { import Option Option } from 'byenull';
const const option: Option.Option<never> option = import Option Option .function pipe<Option.Option<never>, Option.Option<never>>(a: Option.Option<never>, ab: (a: Option.Option<never>) => Option.Option<never>): Option.Option<never> (+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.@exampleimport { 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.@exampleimport { Option } from 'byenull';
const option = Option.none();
// { type: 'None' }
@categoryCreators none (),
import Option Option .function inspect<Option.Option<never>, void>(fn: (a: never) => void): (option: Option.Option<never>) => Option.Option<never> (+1 overload)Executes a side effect function on the value of a
Some
in an
Option
or
OptionAsync
,
without modifying the original option. This is useful for debugging, logging, or performing
other side effects while maintaining the original value.
If the input is a
None
, the provided function is never called and the option is returned unchanged.
@typeParamO - The input Option or OptionAsync.@typeParamR - The return type of the inspection function.@exampleSome Case
import { Option } from 'byenull';
const option = Option.pipe(
Option.some(42),
Option.inspect((value) => console.log('Debug:', value)),
);
// Console output: "Debug: 42"
// Option: { type: 'Some', value: 42 }
@exampleNone Case (fn is never called)
import { Option } from 'byenull';
const option = Option.pipe(
Option.none(),
Option.inspect((value: number) => console.log('Debug:', value)),
);
// No console output
// Option: { type: 'None' }
@exampleAsynchronous Side Effect
import { Option } from 'byenull';
const option = await Option.pipe(
Option.some(42),
Option.inspect(async (value) => {
await fetch(`/api/logs?value=${value}`);
}),
);
// { type: 'Some', value: 42 }
@seeinspectNone - For inspecting a None instead.@seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators inspect ((value: number value : number) => var console: Console console .Console.log(...data: any[]): voidThe console.log() static method outputs a message to the console.
log ('Debug:', value: number value )),
);
// No console output
// Option: { type: 'None' }Asynchronous Side Effect
import { import Option Option } from 'byenull';
const const option: Option.Option<number> option = await import Option Option .function pipe<Option.Option<number>, Option.OptionAsync<number>>(a: Option.Option<number>, ab: (a: Option.Option<number>) => Option.OptionAsync<number>): Option.OptionAsync<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.@exampleimport { 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.@exampleimport { Option } from 'byenull';
const some = Option.some(42);
// { type: 'Some', value: 42 }
const none = Option.some(null);
// { type: 'None' }
@categoryCreators some (42),
import Option Option .function inspect<Option.Option<number>, Promise<void>>(fn: (a: number) => Promise<void>): (option: Option.Option<number>) => Option.OptionAsync<number> (+1 overload)Executes a side effect function on the value of a
Some
in an
Option
or
OptionAsync
,
without modifying the original option. This is useful for debugging, logging, or performing
other side effects while maintaining the original value.
If the input is a
None
, the provided function is never called and the option is returned unchanged.
@typeParamO - The input Option or OptionAsync.@typeParamR - The return type of the inspection function.@exampleSome Case
import { Option } from 'byenull';
const option = Option.pipe(
Option.some(42),
Option.inspect((value) => console.log('Debug:', value)),
);
// Console output: "Debug: 42"
// Option: { type: 'Some', value: 42 }
@exampleNone Case (fn is never called)
import { Option } from 'byenull';
const option = Option.pipe(
Option.none(),
Option.inspect((value: number) => console.log('Debug:', value)),
);
// No console output
// Option: { type: 'None' }
@exampleAsynchronous Side Effect
import { Option } from 'byenull';
const option = await Option.pipe(
Option.some(42),
Option.inspect(async (value) => {
await fetch(`/api/logs?value=${value}`);
}),
);
// { type: 'Some', value: 42 }
@seeinspectNone - For inspecting a None instead.@seepipe - It is recommended to use this function with the pipe function for better readability and composability.@categoryCombinators inspect (async (value: number value ) => {
await function fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> fetch (`/api/logs?value=${value: number value }`);
}),
);
// { type: 'Some', value: 42 }#See
- inspectNone - For inspecting a None instead.
- pipe - It is recommended to use this function with the pipe function for better readability and composability.
#Call Signature
inspect<
O,R>(fn): (option) =>OptionFor<O|R,InferSome<O>>
#Type Parameters
#O
O extends OptionMaybeAsync<any>
#R
R extends void | Promise<void>
#Parameters
#fn
(a) => R
#Returns
(option) => OptionFor<O | R, InferSome<O>>
#Call Signature
inspect<
F>(fn): <O>(option) =>OptionFor<O|ReturnType<F>,InferSome<O>>
#Type Parameters
#F
F extends (a) => void | Promise<void>
#Parameters
#fn
F