None if the Option is None, otherwise returns optionB.
Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use andThen, which is lazily evaluated.
Transforms the Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).
Arguments passed to okOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use okOrElse, which is lazily evaluated.
the Option if it contains a value, otherwise returns optionB.
Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use orElse, which is lazily evaluated.
Arguments passed to unwrapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse, which is lazily evaluated.
Arguments passed to unwrapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse, which is lazily evaluated.
the Result if it is Ok, otherwise returns resultB.
Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use orElse, which is lazily evaluated.
Arguments passed to unwrapErrOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapErrOrElse, which is lazily evaluated.
Arguments passed to unwrapErrOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapErrOrElse, which is lazily evaluated.
Arguments passed to unwrapOr are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrapOrElse, which is lazily evaluated.
The
Option
type is an immutable representation of an optional value: +- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Class Option<T>
The
-Option
type is an immutable representation of an optional value: everyOption
is eitherSome
and contains a value, orNone
and does not.Type Parameters
Index
Properties
Type Parameters
Index
Properties
Methods
Properties
Static
NoneThe
-None
value.Methods
[iterator]
Returns an iterator over the possibly contained value.
+Methods
[iterator]
Returns an iterator over the possibly contained value.
The iterator yields one value if the result is
-Some
, otherwise none.Returns Generator<T, void, unknown>
and
Type Parameters
Parameters
An
+Option
Returns Generator<T, void, unknown>
and
Type Parameters
Parameters
An
Option
Returns Option<B>
None
if theOption
isNone
, otherwise returnsoptionB
.Arguments passed to
-and
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useandThen
, which is lazily evaluated.and Then
Type Parameters
Parameters
A function that returns an
+Option
and Then
Type Parameters
Parameters
A function that returns an
Option
Parameters
Returns Option<B>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<B>
-None
if theOption
isNone
, otherwise callsgetOptionB
with the wrapped value and returns the result.filter
Returns
+None
if theOption
isNone
, otherwise calls predicate with the wrapped value and returns:filter
Returns
None
if theOption
isNone
, otherwise calls predicate with the wrapped value and returns:Some(t)
if predicate returnstrue
(wheret
is the wrapped value with inferred new type), andNone
if predicate returnsfalse
.Type Parameters
Parameters
A type predicate function that defines type guard by returning
true
orfalse
.Parameters
Returns value is U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
-undefined
is used instead.Returns Option<U>
Returns
+None
if theOption
isNone
, otherwise calls predicate with the wrapped value and returns:Returns Option<U>
Returns
None
if theOption
isNone
, otherwise calls predicate with the wrapped value and returns:Some(t)
if predicate returnstrue
(wheret
is the wrapped value), andNone
if predicate returnsfalse
.Parameters
A function that returns
true
orfalse
.Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
-undefined
is used instead.Returns Option<T>
flatten
Converts from
-Option<Option<T>>
toOption<T>
Returns Option<UnwrapOption<T, T>>
is None
Returns boolean
-true
if theOption
is aNone
.is Same
Whether
+this
value is the same as the otherOption
.Returns Option<T>
flatten
Converts from
+Option<Option<T>>
toOption<T>
Returns Option<UnwrapOption<T, T>>
is None
Returns boolean
+true
if theOption
is aNone
.is Same
Whether
this
value is the same as the otherOption
.Parameters
Another
Option
or any valueReturns boolean
-true
if the other is anOption
and the value are the same asthis
value viaObject.is
.is Some
Returns boolean
-true
if theOption
is aSome
.is Some And
Parameters
A function that returns
+true
if the value satisfies the predicate, otherwisefalse
is Some
Returns boolean
+true
if theOption
is aSome
.is Some And
Parameters
A function that returns
true
if the value satisfies the predicate, otherwisefalse
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns boolean
-true
if theOption
is aSome
and and the value inside of it matches a predicate.map
Maps an
+Option<T>
toOption<U>
by applying a function to a contained value (ifSome
) or returnsNone
(ifNone
).map
Maps an
Option<T>
toOption<U>
by applying a function to a contained value (ifSome
) or returnsNone
(ifNone
).Type Parameters
Parameters
A function that maps a value to another value
Parameters
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<U>
-None
if theOption
isNone
, otherwise returnsSome(fn(value))
.match
Extract the value from an
+Option
in a way that handles both theSome
andNone
cases.match
Extract the value from an
Option
in a way that handles both theSome
andNone
cases.Type Parameters
Parameters
A function that returns a value if the
Option
is aSome
.Parameters
Returns U
A function that returns a value if the
Option
is aNone
.Returns U
Returns U
The value returned by the provided function.
-ok Or
Transforms the
+Option<T>
into aResult<T, E>
, mappingSome(v)
toOk(v)
and None toErr(err)
.ok Or
Transforms the
Option<T>
into aResult<T, E>
, mappingSome(v)
toOk(v)
and None toErr(err)
.Arguments passed to
okOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useokOrElse
, which is lazily evaluated.Type Parameters
Parameters
The error value for
-Err
if theOption
isNone
.Returns Result<T, E>
ok Or Else
Transforms the
+Option<T>
into aResult<T, E>
, mappingSome(v)
toOk(v)
andNone
toErr(err())
.Returns Result<T, E>
ok Or Else
Transforms the
Option<T>
into aResult<T, E>
, mappingSome(v)
toOk(v)
andNone
toErr(err())
.Type Parameters
Parameters
A function that returns the error value for
Err
if theOption
isNone
.Returns E
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
-undefined
is used instead.Returns Result<T, E>
or
Type Parameters
Parameters
An
+Option
Returns Result<T, E>
or
Type Parameters
Parameters
An
Option
Returns Option<T | B>
the
Option
if it contains a value, otherwise returnsoptionB
.Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use
-orElse
, which is lazily evaluated.or Else
Type Parameters
Parameters
A function that returns an
+Option
or Else
Type Parameters
Parameters
A function that returns an
Option
Returns Option<B>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<T | B>
the
-Option
if it contains a value, otherwise callsgetOptionB
and returns the result.to String
Returns string
transpose
Transposes an
+Option(Result)
intoResult(Option)
.to String
Returns string
transpose
Transposes an
Option(Result)
intoResult(Option)
.None
will be mapped toOk(None)
.Some(Ok(_))
andSome(Err(_))
will be mapped toOk(Some(_))
andErr(_)
.Some(value)
will be mapped toOk(Some(value))
.Returns Result<Option<UnwrapOk<T>>, UnwrapErr<T>>
unwrap
Parameters
Optional Error message
+Returns Result<Option<UnwrapOk<T>>, UnwrapErr<T>>
unwrap
Parameters
Optional Error message
Returns T
the contained
Some
value.Throws
if the value is a None.
-unwrap Or
Returns undefined | T
the contained
+Some
value orundefined
otherwise.unwrap Or
Returns undefined | T
the contained
Some
value orundefined
otherwise.Arguments passed to
-unwrapOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useunwrapOrElse
, which is lazily evaluated.Type Parameters
Parameters
default value
+Type Parameters
Parameters
default value
Returns T | U
the contained
Some
value or a provided default.Arguments passed to
-unwrapOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useunwrapOrElse
, which is lazily evaluated.unwrap Or Else
Type Parameters
Parameters
A function that computes a default value.
+unwrap Or Else
Type Parameters
Parameters
A function that computes a default value.
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns T | U
the contained
-Some
value or computes it from a closure.unzip
? T<T>[0]
: unknown>, Option<T extends any[]
? T<T>[1]
: unknown>]
Unzips an
+Option
containing a tuple of twoOption
s.unzip
? T<T>[0]
: unknown>, Option<T extends any[]
? T<T>[1]
: unknown>]
Unzips an
Option
containing a tuple of twoOption
s.Returns [Option<T extends any[]
? T<T>[0]
: unknown>, Option<T extends any[]
? T<T>[1]
: unknown>]
-[Some(a), Some(b)]
ifthis
isSome([a, b])
, otherwise[None, None]
.xor
Type Parameters
Parameters
An
+Option
xor
Type Parameters
Parameters
An
Option
Returns Option<T | B>
-Some
if exactly one ofthis
andoptionB
isSome
, otherwise returnsNone
.zip
Zips
+this
with anotherOption
.zip
Zips
this
with anotherOption
.Type Parameters
Parameters
Returns Option<[T, B]>
-Some([a, b])
ifthis
isSome(a)
and other isSome(b)
, otherwiseNone
.zip With
Zips
+this
and anotherOption
with functionfn
.zip With
Zips
this
and anotherOption
with functionfn
.Type Parameters
Parameters
Parameters
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<U>
-Some(fn(a, b))
ifthis
isSome(a)
and other isSome(b)
, otherwiseNone
.Static
fromWrap a value in an
+Option
if the value is truthy.Static
fromWrap a value in an
Option
if the value is truthy.Type Parameters
Parameters
A value of type
-T
Returns Option<Exclude<T, Falsy>>
Wrap a value in an
+Option
if the value satisfies the predicate.Returns Option<Exclude<T, Falsy>>
Wrap a value in an
Option
if the value satisfies the predicate.Type Parameters
Parameters
Source value
A function that returns
true
if the value satisfies the predicate, otherwisefalse
Parameters
Returns source is T
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
-undefined
is used instead.Returns Option<T>
Wrap a value in an
+Option
if the value satisfies the predicate.Returns Option<T>
Wrap a value in an
Option
if the value satisfies the predicate.Type Parameters
Parameters
Source value
A function that returns
-true
if the value satisfies the predicate, otherwisefalse
Parameters
Returns boolean
Optional
thisArg: anyReturns Option<T>
Static
isType Parameters
Parameters
A value that might be an
+Option
Parameters
Returns boolean
Optional
thisArg: anyReturns Option<T>
Static
isType Parameters
Parameters
A value that might be an
Option
Returns maybeOption is Option<T>
-true
if the given value is anOption
.Static
isParameters
An
+Option
or any valueStatic
isParameters
An
Option
or any valueAn
Option
or any valueReturns boolean
-true
if the both areOption
and the value are the same viaObject.is
.Static
SomeType Parameters
Parameters
A value of type
+T
Static
SomeType Parameters
Parameters
A value of type
T
Returns Option<T>
Wrap a value into an
-Option
.Static
unwrapType Parameters
Parameters
A value of type
+T
or anOption<T>
Static
unwrapType Parameters
Parameters
A value of type
T
or anOption<T>
Returns undefined | T
the
-unwrapOr()
result if the value is anOption
, otherwise the value itself.Settings
On This Page
Properties
Methods
Settings
On This Page
Properties
Methods
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Class Result<T, E>
The
-Result
type is an immutable representation of either success (Ok
) or failure (Err
).Type Parameters
Index
Methods
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Class Result<T, E>
The
+Result
type is an immutable representation of either success (Ok
) or failure (Err
).Type Parameters
Index
Methods
Methods
[iterator]
Returns an iterator over the possibly contained value.
The iterator yields one value if the result is
-Ok
, otherwise none.Returns Generator<T, void, unknown>
and
Type Parameters
Parameters
Returns Result<BT, E | BE>
and Then
Type Parameters
Parameters
A function that returns a
+Result
Returns Generator<T, void, unknown>
and
Type Parameters
Parameters
Returns Result<BT, E | BE>
and Then
Type Parameters
Parameters
A function that returns a
Result
Parameters
Returns Result<BT, BE>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Result<BT, E | BE>
-Err
if theResult
isErr
, otherwise callsgetOptionB
with the wrapped value and returns the result.err
Converts from
-Result<T, E>
toOption<E>
and discarding the value, if any.Returns Option<E>
flatten
Converts from
-Option<Option<T>>
toOption<T>
Returns Result<UnwrapOk<T, T>, E | UnwrapErr<E, E>>
is Err
Returns boolean
-true
if theResult
is anErr
.is Err And
Parameters
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
+undefined
is used instead.err
Converts from
+Result<T, E>
toOption<E>
and discarding the value, if any.Returns Option<E>
flatten
Converts from
+Option<Option<T>>
toOption<T>
Returns Result<UnwrapOk<T, T>, E | UnwrapErr<E, E>>
is Err
Returns boolean
+true
if theResult
is anErr
.is Err And
Parameters
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns boolean
-true
if theResult
is anErr
and and the error inside of it matches a predicate.is Ok
Returns boolean
-true
if theResult
is anOk
.is Ok And
Parameters
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
+undefined
is used instead.is Ok
Returns boolean
+true
if theResult
is anOk
.is Ok And
Parameters
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns boolean
-true
if theResult
is anOk
and and the value inside of it matches a predicate.is Same
Whether
+this
Ok
value orErr
error is the same as the otherResult
.is Same
Whether
this
Ok
value orErr
error is the same as the otherResult
.Parameters
Another
Result
or any valueReturns boolean
-true
if the other is anResult
and theOk
value orErr
error is the same asthis
viaObject.is
.map
Maps an
+Result<T, E>
toResult<U, E>
by applying a function to a containedOk
value, leaving anErr
value untouched.map
Maps an
Result<T, E>
toResult<U, E>
by applying a function to a containedOk
value, leaving anErr
value untouched.Type Parameters
Parameters
A function that maps a value to another value
Parameters
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Result<U, E>
-Err
if theResult
isErr
, otherwise returnsOk(fn(value))
.map Err
Maps a
+Result<T, E>
toResult<T, F>
by applying a function to a containedErr
value, leaving anOk
value untouched.map Err
Maps a
Result<T, E>
toResult<T, F>
by applying a function to a containedErr
value, leaving anOk
value untouched.This function can be used to pass through a successful result while handling an error.
Type Parameters
Parameters
A function that maps a error to another error
Parameters
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Result<T, U>
-Ok
if theResult
isOk
, otherwise returnsErr(fn(error))
.match
Extract the value from an
+Result
in a way that handles both theOk
andErr
cases.match
Extract the value from an
Result
in a way that handles both theOk
andErr
cases.Type Parameters
Parameters
A function that returns a value if the
Result
is aOk
.Parameters
Returns U
A function that returns a value if the
Result
is aErr
.Parameters
Returns U
Returns U
The value returned by the provided function.
-ok
Converts from
-Result<T, E>
toOption<T>
and discarding the error, if any.Returns Option<T>
or
Type Parameters
Parameters
A
+Result
ok
Converts from
+Result<T, E>
toOption<T>
and discarding the error, if any.Returns Option<T>
or
Type Parameters
Parameters
A
Result
Returns Result<T | BT, E | BE>
the
Result
if it isOk
, otherwise returnsresultB
.Arguments passed to
-or
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useorElse
, which is lazily evaluated.or Else
Type Parameters
Parameters
A function that returns an
+Result
or Else
Type Parameters
Parameters
A function that returns an
Result
Returns Result<BT, BE>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Result<T | BT, E | BE>
the
-Result
if it contains a value, otherwise callsgetResultB
and returns the result.to String
Returns string
transpose
Transposes a
+Result(Option)
intoOption(Result)
.to String
Returns string
transpose
Transposes a
Result(Option)
intoOption(Result)
.Ok(Some(_))
will be mapped to `Some(Ok(_))Err(_)
will be mapped toSome(Err(_))
.Ok(_)
will be mapped toSome(Ok(_))
.Returns Option<Result<UnwrapOption<T>, E>>
unwrap
Parameters
Optional Error message
+Returns Option<Result<UnwrapOption<T>, E>>
unwrap
Parameters
Optional Error message
Returns T
the contained
Ok
value.Throws
if the value is an
-Err
.unwrap Err
Parameters
Optional Error message
+unwrap Err
Parameters
Optional Error message
Returns E
the contained
Err
error.Throws
if the error is an
-Ok
.unwrap Err Or
Returns undefined | E
the contained
+Err
error orundefined
otherwise.unwrap Err Or
Returns undefined | E
the contained
Err
error orundefined
otherwise.Arguments passed to
-unwrapErrOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useunwrapErrOrElse
, which is lazily evaluated.Type Parameters
Parameters
default error
+Type Parameters
Parameters
default error
Returns E | U
the contained
Err
error or a provided default.Arguments passed to
-unwrapErrOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useunwrapErrOrElse
, which is lazily evaluated.unwrap Err Or Else
Type Parameters
Parameters
A function that computes a default value.
+unwrap Err Or Else
Type Parameters
Parameters
A function that computes a default value.
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns E | U
the contained
-Err
error or computes it from a closure.unwrap Or
Returns undefined | T
the contained
-Ok
value orundefined
otherwise.Type Parameters
Parameters
default value
+unwrap Or
Returns undefined | T
the contained
+Ok
value orundefined
otherwise.Type Parameters
Parameters
default value
Returns T | U
the contained
Ok
value or a provided default.Arguments passed to
-unwrapOr
are eagerly evaluated; if you are passing the result of a function call, it is recommended to useunwrapOrElse
, which is lazily evaluated.unwrap Or Else
Type Parameters
Parameters
A function that computes a default value.
+unwrap Or Else
Type Parameters
Parameters
A function that computes a default value.
Returns U
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns T | U
the contained
-Ok
value or computes it from a closure.Static
Readonly
ErrType Parameters
Parameters
An error of type
+E
Static
Readonly
ErrType Parameters
Parameters
An error of type
E
Returns Result<T, E>
Wrap an error into an
-Result
.Static
from
-Err
if the value is anError
.Type Parameters
Parameters
Returns Result<T, E>
+OK
if the value satisfies the predicate, otherwiseErr
Static
from
+Err
if the value is anError
.Type Parameters
Parameters
Returns Result<T, E>
OK
if the value satisfies the predicate, otherwiseErr
Type Parameters
Parameters
Source value
A function that returns
true
if the value satisfies the predicate, otherwisefalse
Parameters
Returns source is T
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
-undefined
is used instead.Returns Result<T, E>
+OK
if the value satisfies the predicate, otherwiseErr
Returns Result<T, E>
OK
if the value satisfies the predicate, otherwiseErr
Type Parameters
Parameters
Source value
A function that returns
true
if the value satisfies the predicate, otherwisefalse
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
-undefined
is used instead.Returns Result<T, E>
Static
isType Parameters
Parameters
A value that might be an
+Result
Returns Result<T, E>
Static
isType Parameters
Parameters
A value that might be an
Result
Returns maybeResult is Result<T, E>
-true
if the given value is anResult
.Static
isParameters
An
+Result
or any valueStatic
isParameters
An
Result
or any valueAn
Result
or any valueReturns boolean
-true
if the both areResult
and theOk
value orErr
error are the same viaObject.is
.Static
Readonly
OkType Parameters
Parameters
A value of type
+T
Static
Readonly
OkType Parameters
Parameters
A value of type
T
Returns Result<T, E>
Wrap a value into an
-Result
.Static
try
+Ok
if thefn
returns a value,Err
if thefn
throws.Static
tryOk
if thefn
returns a value,Err
if thefn
throws.Type Parameters
Parameters
Parameters
Rest
...args: TArgsReturns T
Rest
...args: TArgsReturns Result<T, E>
-Ok
with the returned value orErr
with the exception error.Static
try
+Ok
if thefn
returned Promise resolves a value,Err
if thefn
throws or the Promise rejected.Static
tryOk
if thefn
returned Promise resolves a value,Err
if thefn
throws or the Promise rejected.Type Parameters
Parameters
Parameters
Rest
...args: TArgsReturns T
Rest
...args: TArgsReturns Promise<Result<T, E>>
-Ok
with the resolved value orErr
with the exception error or the rejected value.Settings
On This Page
Methods
Settings
On This Page
Methods
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function Err
Param: error
An error of type
+E
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function Err
Param: error
An error of type
E
Returns
Wrap an error into an
Result
.Type Parameters
Parameters
An error of type
E
Returns Result<T, E>
Wrap an error into an
-Result
.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function Ok
Param: value
A value of type
+T
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function Ok
Param: value
A value of type
T
Returns
Wrap a value into an
Result
.Type Parameters
Parameters
A value of type
T
Returns Result<T, E>
Wrap a value into an
-Result
.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function Some
Param: value
A value of type
+T
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function Some
Param: value
A value of type
T
Returns
Wrap a value into an
Option
.Type Parameters
Parameters
A value of type
T
Returns Option<T>
Wrap a value into an
-Option
.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function filterMap
+filterMap
filers and maps an iterable at the same time.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function filterMap
filterMap
filers and maps an iterable at the same time.It makes chains of
filter
andmap
more concise, as it shortensmap().filter().map()
to a single call.Type Parameters
Parameters
An array
A function that produces an
Option
.Parameters
Returns Option<U>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns U[]
An array of filtered and mapped values.
-Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function first
+first
finds the first item that matches a predicate. Returns the first item of array if no predicate is provided.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function first
first
finds the first item that matches a predicate. Returns the first item of array if no predicate is provided.Type Parameters
Parameters
An array
A predicate function.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, the first element is returned.
Returns Option<T>
The first item that matches the predicate, or
-None
if no item matches.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function firstIndex
Returns the index of the first element in the array that satisfies the provided testing function. Otherwise
+None
is returned.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function firstIndex
Returns the index of the first element in the array that satisfies the provided testing function. Otherwise
None
is returned.Type Parameters
Parameters
An array
A predicate function.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<number>
The index of the first item that matches the predicate, or
-None
if no item matches.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function firstMap
Applies function to the elements of iterator and returns the first non-none result.
+- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function firstMap
Applies function to the elements of iterator and returns the first non-none result.
firstMap(fn)
is the lighter version offilterMap(fn).first()
.Type Parameters
Parameters
An array
A function that produces an
Option
.Parameters
Returns Option<U>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<U>
The first non-none result.
-Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function last
+last
finds the last item that matches a predicate. Returns the last item of array if no predicate is provided.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function last
last
finds the last item that matches a predicate. Returns the last item of array if no predicate is provided.Type Parameters
Parameters
An array
A predicate function.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided, the last element is returned.
Returns Option<T>
The last item that matches the predicate, or
-None
if no item matches.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function lastIndex
Returns the index of the last element in the array where predicate is true, and
+None
otherwise.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function lastIndex
Returns the index of the last element in the array where predicate is true, and
None
otherwise.Type Parameters
Parameters
An array
lastIndex calls predicate once for each element of the array, in backward order, until it finds one where predicate returns true.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<number>
The index of the last item that matches the predicate, or
-None
if no item matches.Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function lastMap
+lastMap(fn)
is the lighter version offilterMap(fn).last()
.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function lastMap
lastMap(fn)
is the lighter version offilterMap(fn).last()
.Type Parameters
Parameters
An array
A function that produces an
Option
.Parameters
Returns Option<U>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<U>
The last non-none result.
-Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function mapWhile
+mapWhile
maps an iterable until the firstNone
is encountered.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function mapWhile
mapWhile
maps an iterable until the firstNone
is encountered.Type Parameters
Parameters
An array
A function that produces an
Option
.Parameters
Returns Option<U>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns U[]
An array of mapped values.
-Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Function reduceWhile
+reduceWhile
reduces an iterable until the firstNone
is encountered.- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Function reduceWhile
reduceWhile
reduces an iterable until the firstNone
is encountered.Type Parameters
Parameters
An array
A function that produces an
Option
.Parameters
Returns Option<U>
The initial value.
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns U
The reduced value.
-Settings
Settings
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4@wopjs/tsur - v0.1.4
tsur
+
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5@wopjs/tsur - v0.1.5
tsur
@@ -30,4 +30,4 @@
See docs for more details.
License
MIT @ CRIMX
-Settings
On This Page
Settings
On This Page
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Interface ResultMatcher<T, E, U>
Err: ((error: E) => U);
Ok: ((value: T) => U);
}
Type Parameters
Index
Properties
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Interface ResultMatcher<T, E, U>
Err: ((error: E) => U);
Ok: ((value: T) => U);
}
Type Parameters
Index
Properties
Properties
Err
Ok
Settings
On This Page
Properties
Properties
Err
Ok
Settings
On This Page
Properties
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.4Interface Array<T>
$filterMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): U[];
$first(predicate?: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<T>;
$firstIndex(predicate: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<number>;
$firstMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): Option<U>;
$last(predicate?: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<T>;
$lastIndex(predicate: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<number>;
$lastMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): Option<U>;
$mapWhile<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): U[];
$reduceWhile<U>(fn: ((previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Option<U>), initialValue: U, thisArg?: any): U;
}
Type Parameters
Index
Methods
- Preparing search index...
- The search index is not available
@wopjs/tsur - v0.1.5Interface Array<T>
$filterMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): U[];
$first(predicate?: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<T>;
$firstIndex(predicate: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<number>;
$firstMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): Option<U>;
$last(predicate?: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<T>;
$lastIndex(predicate: ((value: T, index: number, array: T[]) => boolean), thisArg?: any): Option<number>;
$lastMap<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): Option<U>;
$mapWhile<U>(fn: ((value: T, index: number, array: T[]) => Option<U>), thisArg?: any): U[];
$reduceWhile<U>(fn: ((previousValue: U, currentValue: T, currentIndex: number, array: T[]) => Option<U>), initialValue: U, thisArg?: any): U;
}
Type Parameters
Index
Methods
Type Parameters
Parameters
A function that produces an
Option
.Parameters
Returns Option<U>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns U[]
An array of filtered and mapped values.
-$first
From tsur.
+$first
From tsur.
first
finds the first item that matches a predicate. Returns the first item of array if no predicate is provided.Parameters
Optional
predicate: ((value: T, index: number, array: T[]) => boolean)A predicate function.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<T>
The first item that matches the predicate, or
-None
if no item matches.$first Index
From tsur.
+$first Index
From tsur.
Returns the index of the first element in the array that satisfies the provided testing function. Otherwise
None
is returned.Parameters
A predicate function.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<number>
The index of the first item that matches the predicate, or
-None
if no item matches.$first Map
From tsur.
+$first Map
From tsur.
Applies function to the elements of iterator and returns the first non-none result.
firstMap(fn)
is the lighter version offilterMap(fn).first()
.Type Parameters
Parameters
A function that produces an
Option
.Parameters
Returns Option<U>
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<U>
The first non-none result.
-$last
From tsur.
+$last
From tsur.
last
finds the last item that matches a predicate. Returns the last item of array if no predicate is provided.Parameters
Optional
predicate: ((value: T, index: number, array: T[]) => boolean)A predicate function.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<T>
The last item that matches the predicate, or
-None
if no item matches.$last Index
From tsur.
+$last Index
From tsur.
Returns the index of the last element in the array where predicate is true, and
None
otherwise.Parameters
lastIndex calls predicate once for each element of the array, in backward order, until it finds one where predicate returns true.
Parameters
Returns boolean
Optional
thisArg: anyIf provided, it will be used as the this value for each invocation of predicate. If it is not provided,
undefined
is used instead.Returns Option<number>
The index of the last item that matches the predicate, or
-None
if no item matches.$last Map
From tsur.
+$last Map
From tsur.
lastMap(fn)
is the lighter version offilterMap(fn).last()
.Type Parameters
Parameters
A function that produces an
Option
.Parameters