- Alt
- Alternative
- Applicative
- Apply
- Chain
- ChainRec
- Compactable
- Extend
- Filterable
- Foldable
- FromEither
- Functor
- Monad
- MonadThrow
- Pointed
- Traversable
- Witherable
- Zero
- getEq
- getMonoid
- getOrd
- getShow
- sequence
- sequenceArray
- traverse
- traverseArray
- traverseArrayWithIndex
- traverseReadonlyArrayWithIndex
- traverseReadonlyNonEmptyArrayWithIndex
- ApT
- ap
- apFirst
- apSecond
- do
- duplicate
- elem
- exists
- extend
getApplyMonoid(deprecated)getApplySemigroup(deprecated)getFirstMonoid(deprecated)getLastMonoid(deprecated)getRefinement(deprecated)- let
mapNullable(deprecated)option(deprecated)- throwError
- zero
export declare const Alt: Alt1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Alternative: Alternative1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Applicative: Applicative1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Apply: Apply1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Chain: chainable.Chain1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
ChainRec for Option
export declare const ChainRec: ChainRec1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2022-present Jacob Alford
export declare const Compactable: Compactable1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Extend: Extend1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Filterable: Filterable1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Foldable: Foldable1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const FromEither: FromEither1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Functor: Functor1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Monad: Monad1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const MonadThrow: MonadThrow1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Pointed: Pointed1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Traversable: Traversable1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Witherable: Witherable1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Zero: Zero1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const getEq: <A>(E: Eq<A>) => Eq<Option<A>>
- Added in 0.1.0
import { none, some, getEq } from '@fp-tx/core/Option'
import * as N from '@fp-tx/core/number'
const E = getEq(N.Eq)
assert.strictEqual(E.equals(none, none), true)
assert.strictEqual(E.equals(none, some(1)), false)
assert.strictEqual(E.equals(some(1), none), false)
assert.strictEqual(E.equals(some(1), some(2)), false)
assert.strictEqual(E.equals(some(1), some(1)), true)
- MIT – Copyright (c) 2017-present Giulio Canti
Monoid returning the left-most non-None
value. If both operands are Some
s then the inner values are concatenated using the provided Semigroup
| x | y | concat(x, y) | | ------- | ------- | ------------------ | | none | none | none | | some(a) | none | some(a) | | none | some(b) | some(b) | | some(a) | some(b) | some(concat(a, b)) |
export declare const getMonoid: <A>(S: Semigroup<A>) => Monoid<Option<A>>
- Added in 0.1.0
import { getMonoid, some, none } from '@fp-tx/core/Option'
import { SemigroupSum } from '@fp-tx/core/number'
const M = getMonoid(SemigroupSum)
assert.deepStrictEqual(M.concat(none, none), none)
assert.deepStrictEqual(M.concat(some(1), none), some(1))
assert.deepStrictEqual(M.concat(none, some(1)), some(1))
assert.deepStrictEqual(M.concat(some(1), some(2)), some(3))
- MIT – Copyright (c) 2017-present Giulio Canti
The Ord
instance allows Option
values to be compared with compare
, whenever there is an Ord
instance for the type the Option
contains.
None
is considered to be less than any Some
value.
export declare const getOrd: <A>(O: Ord<A>) => Ord<Option<A>>
- Added in 0.1.0
import { none, some, getOrd } from '@fp-tx/core/Option'
import * as N from '@fp-tx/core/number'
const O = getOrd(N.Ord)
assert.strictEqual(O.compare(none, none), 0)
assert.strictEqual(O.compare(none, some(1)), -1)
assert.strictEqual(O.compare(some(1), none), 1)
assert.strictEqual(O.compare(some(1), some(2)), -1)
assert.strictEqual(O.compare(some(1), some(1)), 0)
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const getShow: <A>(S: Show<A>) => Show<Option<A>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
export declare const tap: {
<A, _>(self: Option<A>, f: (a: A) => Option<_>): Option<A>
<A, _>(f: (a: A) => Option<_>): (self: Option<A>) => Option<A>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Composes computations in sequence, using the return value of one computation to determine the next computation and keeping only the result of the first.
export declare const tapEither: {
<A, E, _>(f: (a: A) => Either<E, _>): (self: Option<A>) => Option<A>
<A, E, _>(self: Option<A>, f: (a: A) => Either<E, _>): Option<A>
}
- Added in 0.1.0
import { pipe } from '@fp-tx/core/function'
import * as O from '@fp-tx/core/Option'
import * as E from '@fp-tx/core/Either'
const compute = (value: number) =>
pipe(
O.of(value),
O.tapEither(value => (value > 0 ? E.right('ok') : E.left('error'))),
)
assert.deepStrictEqual(compute(1), O.of(1))
assert.deepStrictEqual(compute(-42), O.none)
- MIT – Copyright (c) 2017-present Giulio Canti
Returns the Left
value of an Either
if possible.
export declare const getLeft: <E, A>(ma: Either<E, A>) => Option<E>
- Added in 0.1.0
import { getLeft, none, some } from '@fp-tx/core/Option'
import { right, left } from '@fp-tx/core/Either'
assert.deepStrictEqual(getLeft(right(1)), none)
assert.deepStrictEqual(getLeft(left('a')), some('a'))
- MIT – Copyright (c) 2017-present Giulio Canti
Returns the Right
value of an Either
if possible.
export declare const getRight: <E, A>(ma: Either<E, A>) => Option<A>
- Added in 0.1.0
import { getRight, none, some } from '@fp-tx/core/Option'
import { right, left } from '@fp-tx/core/Either'
assert.deepStrictEqual(getRight(right(1)), some(1))
assert.deepStrictEqual(getRight(left('a')), none)
- MIT – Copyright (c) 2017-present Giulio Canti
None
doesn't have a constructor, instead you can use it directly as a value. Represents a missing value.
export declare const none: Option<never>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const of: <A>(a: A) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Constructs a Some
. Represents an optional value that exists.
export declare const some: <A>(a: A) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Transforms an Either
to an Option
discarding the error.
Alias of getRight
export declare const fromEither: <A>(fa: Either<unknown, A>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Constructs a new Option
from a nullable type. If the value is null
or undefined
, returns None
, otherwise returns the value wrapped in a Some
.
export declare const fromNullable: <A>(a: A) => Option<NonNullable<A>>
- Added in 0.1.0
import { none, some, fromNullable } from '@fp-tx/core/Option'
assert.deepStrictEqual(fromNullable(undefined), none)
assert.deepStrictEqual(fromNullable(null), none)
assert.deepStrictEqual(fromNullable(1), some(1))
- MIT – Copyright (c) 2017-present Giulio Canti
Extracts the value out of the structure, if it exists. Otherwise returns null
.
export declare const toNullable: <A>(ma: Option<A>) => A | null
- Added in 0.1.0
import { some, none, toNullable } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
assert.strictEqual(pipe(some(1), toNullable), 1)
assert.strictEqual(pipe(none, toNullable), null)
- MIT – Copyright (c) 2017-present Giulio Canti
Extracts the value out of the structure, if it exists. Otherwise returns undefined
.
export declare const toUndefined: <A>(ma: Option<A>) => A | undefined
- Added in 0.1.0
import { some, none, toUndefined } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
assert.strictEqual(pipe(some(1), toUndefined), 1)
assert.strictEqual(pipe(none, toUndefined), undefined)
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const Do: Option<{}>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const apS: <N extends string, A, B>(
name: Exclude<N, keyof A>,
fb: Option<B>,
) => (fa: Option<A>) => Option<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const bind: <N extends string, A, B>(
name: Exclude<N, keyof A>,
f: (a: A) => Option<B>,
) => (ma: Option<A>) => Option<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const bindTo: <N extends string>(name: N) => <A>(fa: Option<A>) => Option<{ readonly [K in N]: A }>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const guard: (b: boolean) => Option<void>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Extracts the value out of the structure, if it exists. Otherwise returns the given default value
export declare const getOrElse: <A>(onNone: LazyArg<A>) => (ma: Option<A>) => A
- Added in 0.1.0
import { some, none, getOrElse } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
assert.strictEqual(
pipe(
some(1),
getOrElse(() => 0),
),
1,
)
assert.strictEqual(
pipe(
none,
getOrElse(() => 0),
),
0,
)
- MIT – Copyright (c) 2017-present Giulio Canti
Less strict version of getOrElse
.
The W
suffix (short for Widening) means that the handler return type will be merged.
export declare const getOrElseW: <B>(onNone: LazyArg<B>) => <A>(ma: Option<A>) => B | A
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Returns the provided Option
that
if self
is None
, otherwise returns self
.
export declare const orElse: {
<B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<A | B>
<A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const compact: <A>(fa: Option<Option<A>>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const filter: {
<A, B extends A>(refinement: Refinement<A, B>): (fa: Option<A>) => Option<B>
<A>(predicate: Predicate<A>): <B extends A>(fb: Option<B>) => Option<B>
<A>(predicate: Predicate<A>): (fa: Option<A>) => Option<A>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const filterMap: <A, B>(f: (a: A) => Option<B>) => (fa: Option<A>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const partition: {
<A, B extends A>(refinement: Refinement<A, B>): (fa: Option<A>) => Separated<Option<A>, Option<B>>
<A>(predicate: Predicate<A>): <B extends A>(fb: Option<B>) => Separated<Option<B>, Option<B>>
<A>(predicate: Predicate<A>): (fa: Option<A>) => Separated<Option<A>, Option<A>>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const partitionMap: <A, B, C>(
f: (a: A) => Either<B, C>,
) => (fa: Option<A>) => Separated<Option<B>, Option<C>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const separate: <A, B>(ma: Option<Either<A, B>>) => Separated<Option<A>, Option<B>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const wilt: PipeableWilt1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const wither: PipeableWither1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: Option<A>) => M
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: Option<A>) => B
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: Option<A>) => B
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const chainRec: ChainRec1<URI>['chainRec']
- Added in 0.1.0
- MIT – Copyright (c) 2022-present Jacob Alford
Transforms an exception into an Option
. If f
throws, returns None
, otherwise returns the output wrapped in a Some
.
See also tryCatchK
.
export declare const tryCatch: <A>(f: LazyArg<A>) => Option<A>
- Added in 0.1.0
import { none, some, tryCatch } from '@fp-tx/core/Option'
assert.deepStrictEqual(
tryCatch(() => {
throw new Error()
}),
none,
)
assert.deepStrictEqual(
tryCatch(() => 1),
some(1),
)
- MIT – Copyright (c) 2017-present Giulio Canti
Converts a function that may throw to one returning a Option
.
export declare const tryCatchK: <A extends readonly unknown[], B>(f: (...a: A) => B) => (...a: A) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of orElse
.
export declare const alt: <A>(that: LazyArg<Option<A>>) => (fa: Option<A>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of orElse
.
Less strict version of alt
.
The W
suffix (short for Widening) means that the return types will be merged.
export declare const altW: <B>(that: LazyArg<Option<B>>) => <A>(fa: Option<A>) => Option<A | B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of flatMap
.
export declare const chain: <A, B>(f: (a: A) => Option<B>) => (ma: Option<A>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of tap
.
export declare const chainFirst: <A, B>(f: (a: A) => Option<B>) => (first: Option<A>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of tapEither
.
export declare const chainFirstEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma: Option<A>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const fromEitherK: <E, A extends ReadonlyArray<unknown>, B>(
f: (...a: A) => Either<E, B>,
) => (...a: A) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Returns a smart constructor from a function that returns a nullable value.
export declare const fromNullableK: <A extends ReadonlyArray<unknown>, B>(
f: (...a: A) => B | null | undefined,
) => (...a: A) => Option<NonNullable<B>>
- Added in 0.1.0
import { fromNullableK, none, some } from '@fp-tx/core/Option'
const f = (s: string): number | undefined => {
const n = parseFloat(s)
return isNaN(n) ? undefined : n
}
const g = fromNullableK(f)
assert.deepStrictEqual(g('1'), some(1))
assert.deepStrictEqual(g('a'), none)
- MIT – Copyright (c) 2017-present Giulio Canti
Returns a smart constructor based on the given predicate.
export declare function fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>
export declare function fromPredicate<A>(predicate: Predicate<A>): <B extends A>(b: B) => Option<B>
export declare function fromPredicate<A>(predicate: Predicate<A>): (a: A) => Option<A>
- Added in 0.1.0
import { none, some, fromPredicate } from '@fp-tx/core/Option'
const getOption = fromPredicate((n: number) => n >= 0)
assert.deepStrictEqual(getOption(-1), none)
assert.deepStrictEqual(getOption(1), some(1))
- MIT – Copyright (c) 2017-present Giulio Canti
Maps the Some
value of this Option
to the specified constant value.
export declare const as: {
<A>(a: A): <_>(self: Option<_>) => Option<A>
<_, A>(self: Option<_>, a: A): Option<A>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Maps the Some
value of this Option
to the void constant value.
export declare const asUnit: <_>(self: Option<_>) => Option<void>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const flap: <A>(a: A) => <B>(fab: Option<(a: A) => B>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const map: <A, B>(f: (a: A) => B) => (fa: Option<A>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export interface None {
readonly _tag: 'None'
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export type Option<A> = None | Some<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export interface Some<A> {
readonly _tag: 'Some'
readonly value: A
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of match
.
export declare const fold: <A, B>(onNone: LazyArg<B>, onSome: (a: A) => B) => (ma: Option<A>) => B
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Alias of matchW
.
export declare const foldW: <B, A, C>(onNone: LazyArg<B>, onSome: (a: A) => C) => (ma: Option<A>) => B | C
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Takes a (lazy) default value, a function, and an Option
value, if the Option
value is None
the default value is returned, otherwise the function is applied to the value inside the Some
and the result is returned.
export declare const match: <A, B>(onNone: LazyArg<B>, onSome: (a: A) => B) => (ma: Option<A>) => B
- Added in 0.1.0
import { some, none, match } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
assert.strictEqual(
pipe(
some(1),
match(
() => 'a none',
a => `a some containing ${a}`,
),
),
'a some containing 1',
)
assert.strictEqual(
pipe(
none,
match(
() => 'a none',
a => `a some containing ${a}`,
),
),
'a none',
)
- MIT – Copyright (c) 2017-present Giulio Canti
Less strict version of match
.
The W
suffix (short for Widening) means that the handler return types will be merged.
export declare const matchW: <B, A, C>(onNone: LazyArg<B>, onSome: (a: A) => C) => (ma: Option<A>) => B | C
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Returns true
if the option is None
, false
otherwise.
export declare const isNone: (fa: Option<unknown>) => fa is None
- Added in 0.1.0
import { some, none, isNone } from '@fp-tx/core/Option'
assert.strictEqual(isNone(some(1)), false)
assert.strictEqual(isNone(none), true)
- MIT – Copyright (c) 2017-present Giulio Canti
Returns true
if the option is an instance of Some
, false
otherwise.
export declare const isSome: <A>(fa: Option<A>) => fa is Some<A>
- Added in 0.1.0
import { some, none, isSome } from '@fp-tx/core/Option'
assert.strictEqual(isSome(some(1)), true)
assert.strictEqual(isSome(none), false)
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const chainEitherK: <E, A, B>(f: (a: A) => Either<E, B>) => (ma: Option<A>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
This is chain
+ fromNullable
, useful when working with optional values.
export declare const chainNullableK: <A, B>(f: (a: A) => B) => (ma: Option<A>) => Option<NonNullable<B>>
- Added in 0.1.0
import { some, none, fromNullable, chainNullableK } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
interface Employee {
readonly company?: {
readonly address?: {
readonly street?: {
readonly name?: string
}
}
}
}
const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }
assert.deepStrictEqual(
pipe(
fromNullable(employee1.company),
chainNullableK(company => company.address),
chainNullableK(address => address.street),
chainNullableK(street => street.name),
),
some('high street'),
)
const employee2: Employee = { company: { address: { street: {} } } }
assert.deepStrictEqual(
pipe(
fromNullable(employee2.company),
chainNullableK(company => company.address),
chainNullableK(address => address.street),
chainNullableK(street => street.name),
),
none,
)
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const flatMap: {
<A, B>(f: (a: A) => Option<B>): (ma: Option<A>) => Option<B>
<A, B>(ma: Option<A>, f: (a: A) => Option<B>): Option<B>
}
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const flatten: <A>(mma: Option<Option<A>>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const sequence: Traversable1<URI>['sequence']
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#sequence(Applicative)
.
export declare const sequenceArray: <A>(arr: ReadonlyArray<Option<A>>) => Option<ReadonlyArray<A>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const traverse: PipeableTraverse1<URI>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#traverse(Applicative)
.
export declare const traverseArray: <A, B>(f: (a: A) => Option<B>) => (as: readonly A[]) => Option<readonly B[]>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#traverseWithIndex(Applicative)
.
export declare const traverseArrayWithIndex: <A, B>(
f: (index: number, a: A) => Option<B>,
) => (as: ReadonlyArray<A>) => Option<ReadonlyArray<B>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyArray#traverseWithIndex(Applicative)
.
export declare const traverseReadonlyArrayWithIndex: <A, B>(
f: (index: number, a: A) => Option<B>,
) => (as: readonly A[]) => Option<readonly B[]>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Equivalent to ReadonlyNonEmptyArray#traverseWithIndex(Applicative)
.
export declare const traverseReadonlyNonEmptyArrayWithIndex: <A, B>(
f: (index: number, a: A) => Option<B>,
) => (as: ReadonlyNonEmptyArray<A>) => Option<ReadonlyNonEmptyArray<B>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export type URI = typeof URI
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const URI = 'Option'
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const ApT: Option<readonly []>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const ap: <A>(fa: Option<A>) => <B>(fab: Option<(a: A) => B>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Combine two effectful actions, keeping only the result of the first.
export declare const apFirst: <B>(second: Option<B>) => <A>(first: Option<A>) => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Combine two effectful actions, keeping only the result of the second.
export declare const apSecond: <B>(second: Option<B>) => <A>(first: Option<A>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const do_: <MA extends OptionIterable<any>, A>(
yieldFunction: (unwrap: <A>(ma: Option<A>) => OptionIterable<A>) => Generator<MA, A>,
) => Option<A>
export declare const duplicate: <A>(ma: Option<A>) => Option<Option<A>>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Returns true
if ma
contains a
export declare function elem<A>(E: Eq<A>): {
(a: A): (ma: Option<A>) => boolean
(a: A, ma: Option<A>): boolean
}
- Added in 0.1.0
import { some, none, elem } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
import * as N from '@fp-tx/core/number'
assert.strictEqual(pipe(some(1), elem(N.Eq)(1)), true)
assert.strictEqual(pipe(some(1), elem(N.Eq)(2)), false)
assert.strictEqual(pipe(none, elem(N.Eq)(1)), false)
- MIT – Copyright (c) 2017-present Giulio Canti
Returns true
if the predicate is satisfied by the wrapped value
export declare const exists: <A>(predicate: Predicate<A>) => (ma: Option<A>) => boolean
- Added in 0.1.0
import { some, none, exists } from '@fp-tx/core/Option'
import { pipe } from '@fp-tx/core/function'
assert.strictEqual(
pipe(
some(1),
exists(n => n > 0),
),
true,
)
assert.strictEqual(
pipe(
some(1),
exists(n => n > 1),
),
false,
)
assert.strictEqual(
pipe(
none,
exists(n => n > 0),
),
false,
)
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const extend: <A, B>(f: (wa: Option<A>) => B) => (wa: Option<A>) => Option<B>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
Use getApplicativeMonoid
instead.
export declare const getApplyMonoid: <A>(M: Monoid<A>) => Monoid<Option<A>>
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
Use getApplySemigroup
instead.
export declare const getApplySemigroup: <A>(S: Semigroup<A>) => Semigroup<Option<A>>
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
Use
import { first } from '@fp-tx/core/Semigroup'
import { getMonoid } from '@fp-tx/core/Option'
getMonoid(first())
Instead.
Monoid returning the left-most non-None
value
| x | y | concat(x, y) | | ------- | ------- | ------------ | | none | none | none | | some(a) | none | some(a) | | none | some(b) | some(b) | | some(a) | some(b) | some(a) |
export declare const getFirstMonoid: <A = never>() => Monoid<Option<A>>
- Added in 0.1.0
- Deprecated
import { getFirstMonoid, some, none } from '@fp-tx/core/Option'
const M = getFirstMonoid<number>()
assert.deepStrictEqual(M.concat(none, none), none)
assert.deepStrictEqual(M.concat(some(1), none), some(1))
assert.deepStrictEqual(M.concat(none, some(2)), some(2))
assert.deepStrictEqual(M.concat(some(1), some(2)), some(1))
- MIT – Copyright (c) 2017-present Giulio Canti
Use
import { last } from '@fp-tx/core/Semigroup'
import { getMonoid } from '@fp-tx/core/Option'
getMonoid(last())
Instead.
Monoid returning the right-most non-None
value
| x | y | concat(x, y) | | ------- | ------- | ------------ | | none | none | none | | some(a) | none | some(a) | | none | some(b) | some(b) | | some(a) | some(b) | some(b) |
export declare const getLastMonoid: <A = never>() => Monoid<Option<A>>
- Added in 0.1.0
- Deprecated
import { getLastMonoid, some, none } from '@fp-tx/core/Option'
const M = getLastMonoid<number>()
assert.deepStrictEqual(M.concat(none, none), none)
assert.deepStrictEqual(M.concat(some(1), none), some(1))
assert.deepStrictEqual(M.concat(none, some(2)), some(2))
assert.deepStrictEqual(M.concat(some(1), some(2)), some(2))
- MIT – Copyright (c) 2017-present Giulio Canti
Use Refinement
module instead.
export declare function getRefinement<A, B extends A>(getOption: (a: A) => Option<B>): Refinement<A, B>
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const let_: <N extends string, A, B>(
name: Exclude<N, keyof A>,
f: (a: A) => B,
) => (fa: Option<A>) => Option<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }>
Use chainNullableK
instead.
export declare const mapNullable: <A, B>(f: (a: A) => B) => (ma: Option<A>) => Option<NonNullable<B>>
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
This instance is deprecated, use small, specific instances instead. For example if a function needs a Functor
instance, pass O.Functor
instead of O.option
(where O
is from import O from 'fp-ts/Option'
)
export declare const option: Monad1<URI> &
Foldable1<URI> &
Alternative1<URI> &
Extend1<URI> &
Witherable1<URI> &
MonadThrow1<URI>
- Added in 0.1.0
- Deprecated
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const throwError: MonadThrow1<URI>['throwError']
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti
export declare const zero: <A>() => Option<A>
- Added in 0.1.0
- MIT – Copyright (c) 2017-present Giulio Canti