PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/@celo/contractkit/node_modules/fp-ts/es6
Просмотр файла: Option.d.ts
/**
* @file If you have worked with JavaScript at all in the past, it is very likely that you have come across a `TypeError` at
* some time (other languages will throw similarly named errors in such a case). Usually this happens because some
* function returns `null` or `undefined` when you were not expecting it and thus not dealing with that possibility in
* your client code.
*
* ```ts
* const as: Array<string> = []
* as[0].trim() // throws TypeError: Cannot read property 'trim' of undefined
* ```
*
* `fp-ts` models the absence of values through the `Option` datatype similar to how Scala, Haskell and other FP languages
* handle optional values. A value of `null` or `undefined` is often abused to represent an absent optional value.
*
* `Option<A>` is a container for an optional value of type `A`. If the value of type `A` is present, the `Option<A>` is
* an instance of `Some<A>`, containing the present value of type `A`. If the value is absent, the `Option<A>` is an
* instance of `None`.
*
* An option could be looked at as a collection or foldable structure with either one or zero elements.
* Another way to look at option is: it represents the effect of a possibly failing computation.
*/
import { Alternative1 } from './Alternative';
import { Compactable1, Separated } from './Compactable';
import { Either } from './Either';
import { Eq } from './Eq';
import { Extend1 } from './Extend';
import { Filterable1 } from './Filterable';
import { Foldable1 } from './Foldable';
import { Lazy, Predicate, Refinement } from './function';
import { Monad1 } from './Monad';
import { Monoid } from './Monoid';
import { Ord } from './Ord';
import { Semigroup } from './Semigroup';
import { Show } from './Show';
import { Traversable1 } from './Traversable';
import { Witherable1 } from './Witherable';
import { MonadThrow1 } from './MonadThrow';
declare module './HKT' {
interface URItoKind<A> {
Option: Option<A>;
}
}
/**
* @since 2.0.0
*/
export declare const URI = "Option";
/**
* @since 2.0.0
*/
export declare type URI = typeof URI;
/**
* @since 2.0.0
*/
export interface None {
readonly _tag: 'None';
}
/**
* @since 2.0.0
*/
export interface Some<A> {
readonly _tag: 'Some';
readonly value: A;
}
/**
* @since 2.0.0
*/
export declare type Option<A> = None | Some<A>;
/**
* @since 2.0.0
*/
export declare const none: Option<never>;
/**
* @since 2.0.0
*/
export declare function some<A>(a: A): Option<A>;
/**
* Returns `true` if the option is an instance of `Some`, `false` otherwise
*
* @example
* import { some, none, isSome } from 'fp-ts/lib/Option'
*
* assert.strictEqual(isSome(some(1)), true)
* assert.strictEqual(isSome(none), false)
*
* @since 2.0.0
*/
export declare function isSome<A>(fa: Option<A>): fa is Some<A>;
/**
* Returns `true` if the option is `None`, `false` otherwise
*
* @example
* import { some, none, isNone } from 'fp-ts/lib/Option'
*
* assert.strictEqual(isNone(some(1)), false)
* assert.strictEqual(isNone(none), true)
*
* @since 2.0.0
*/
export declare function isNone<A>(fa: Option<A>): fa is None;
/**
* We can pattern match using the `fold` function
*
* @example
* import { some, none, fold } from 'fp-ts/lib/Option'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* assert.strictEqual(
* pipe(
* some(1),
* fold(() => 'a none', a => `a some containing ${a}`)
* ),
* 'a some containing 1'
* )
*
* assert.strictEqual(
* pipe(
* none,
* fold(() => 'a none', a => `a some containing ${a}`)
* ),
* 'a none'
* )
*
* @since 2.0.0
*/
export declare function fold<A, B>(onNone: () => B, onSome: (a: A) => B): (ma: Option<A>) => B;
/**
* 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`
*
* @example
* import { none, some, fromNullable } from 'fp-ts/lib/Option'
*
* assert.deepStrictEqual(fromNullable(undefined), none)
* assert.deepStrictEqual(fromNullable(null), none)
* assert.deepStrictEqual(fromNullable(1), some(1))
*
* @since 2.0.0
*/
export declare function fromNullable<A>(a: A | null | undefined): Option<A>;
/**
* Extracts the value out of the structure, if it exists. Otherwise returns `null`.
*
* @example
* import { some, none, toNullable } from 'fp-ts/lib/Option'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* assert.strictEqual(
* pipe(
* some(1),
* toNullable
* ),
* 1
* )
* assert.strictEqual(
* pipe(
* none,
* toNullable
* ),
* null
* )
*
* @since 2.0.0
*/
export declare function toNullable<A>(ma: Option<A>): A | null;
/**
* Extracts the value out of the structure, if it exists. Otherwise returns `undefined`.
*
* @example
* import { some, none, toUndefined } from 'fp-ts/lib/Option'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* assert.strictEqual(
* pipe(
* some(1),
* toUndefined
* ),
* 1
* )
* assert.strictEqual(
* pipe(
* none,
* toUndefined
* ),
* undefined
* )
*
* @since 2.0.0
*/
export declare function toUndefined<A>(ma: Option<A>): A | undefined;
/**
* Extracts the value out of the structure, if it exists. Otherwise returns the given default value
*
* @example
* import { some, none, getOrElse } from 'fp-ts/lib/Option'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* assert.strictEqual(
* pipe(
* some(1),
* getOrElse(() => 0)
* ),
* 1
* )
* assert.strictEqual(
* pipe(
* none,
* getOrElse(() => 0)
* ),
* 0
* )
*
* @since 2.0.0
*/
export declare function getOrElse<A>(onNone: () => A): (ma: Option<A>) => A;
/**
* Returns `true` if `ma` contains `a`
*
* @example
* import { some, none, elem } from 'fp-ts/lib/Option'
* import { eqNumber } from 'fp-ts/lib/Eq'
*
* assert.strictEqual(elem(eqNumber)(1, some(1)), true)
* assert.strictEqual(elem(eqNumber)(2, some(1)), false)
* assert.strictEqual(elem(eqNumber)(1, none), false)
*
* @since 2.0.0
*/
export declare function elem<A>(E: Eq<A>): (a: A, ma: Option<A>) => boolean;
/**
* Returns `true` if the predicate is satisfied by the wrapped value
*
* @example
* import { some, none, exists } from 'fp-ts/lib/Option'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* 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
* )
*
* @since 2.0.0
*/
export declare function exists<A>(predicate: Predicate<A>): (ma: Option<A>) => boolean;
/**
* Returns a smart constructor based on the given predicate
*
* @example
* import { none, some, fromPredicate } from 'fp-ts/lib/Option'
*
* const getOption = fromPredicate((n: number) => n >= 0)
*
* assert.deepStrictEqual(getOption(-1), none)
* assert.deepStrictEqual(getOption(1), some(1))
*
* @since 2.0.0
*/
export declare function fromPredicate<A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>;
export declare function fromPredicate<A>(predicate: Predicate<A>): (a: A) => Option<A>;
/**
* Transforms an exception into an `Option`. If `f` throws, returns `None`, otherwise returns the output wrapped in
* `Some`
*
* @example
* import { none, some, tryCatch } from 'fp-ts/lib/Option'
*
* assert.deepStrictEqual(
* tryCatch(() => {
* throw new Error()
* }),
* none
* )
* assert.deepStrictEqual(tryCatch(() => 1), some(1))
*
* @since 2.0.0
*/
export declare function tryCatch<A>(f: Lazy<A>): Option<A>;
/**
* Returns an `E` value if possible
*
* @since 2.0.0
*/
export declare function getLeft<E, A>(ma: Either<E, A>): Option<E>;
/**
* Returns an `A` value if possible
*
* @since 2.0.0
*/
export declare function getRight<E, A>(ma: Either<E, A>): Option<A>;
/**
* Returns a `Refinement` (i.e. a custom type guard) from a `Option` returning function.
* This function ensures that a custom type guard definition is type-safe.
*
* ```ts
* import { some, none, getRefinement } from 'fp-ts/lib/Option'
*
* type A = { type: 'A' }
* type B = { type: 'B' }
* type C = A | B
*
* const isA = (c: C): c is A => c.type === 'B' // <= typo but typescript doesn't complain
* const isA = getRefinement<C, A>(c => (c.type === 'B' ? some(c) : none)) // static error: Type '"B"' is not assignable to type '"A"'
* ```
*
* @since 2.0.0
*/
export declare function getRefinement<A, B extends A>(getOption: (a: A) => Option<B>): Refinement<A, B>;
/**
* This is `chain` + `fromNullable`, useful when working with optional values
*
* @example
* import { some, none, fromNullable, mapNullable } from 'fp-ts/lib/Option'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* interface Employee {
* company?: {
* address?: {
* street?: {
* name?: string
* }
* }
* }
* }
*
* const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }
*
* assert.deepStrictEqual(
* pipe(
* fromNullable(employee1.company),
* mapNullable(company => company.address),
* mapNullable(address => address.street),
* mapNullable(street => street.name)
* ),
* some('high street')
* )
*
* const employee2: Employee = { company: { address: { street: {} } } }
*
* assert.deepStrictEqual(
* pipe(
* fromNullable(employee2.company),
* mapNullable(company => company.address),
* mapNullable(address => address.street),
* mapNullable(street => street.name)
* ),
* none
* )
*
* @since 2.0.0
*/
export declare function mapNullable<A, B>(f: (a: A) => B | null | undefined): (ma: Option<A>) => Option<B>;
/**
* @since 2.0.0
*/
export declare function getShow<A>(S: Show<A>): Show<Option<A>>;
/**
* @example
* import { none, some, getEq } from 'fp-ts/lib/Option'
* import { eqNumber } from 'fp-ts/lib/Eq'
*
* const E = getEq(eqNumber)
* 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)
*
* @since 2.0.0
*/
export declare function getEq<A>(E: Eq<A>): Eq<Option<A>>;
/**
* 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.
*
*
* @example
* import { none, some, getOrd } from 'fp-ts/lib/Option'
* import { ordNumber } from 'fp-ts/lib/Ord'
*
* const O = getOrd(ordNumber)
* 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)
*
* @since 2.0.0
*/
export declare function getOrd<A>(O: Ord<A>): Ord<Option<A>>;
/**
* `Apply` semigroup
*
* | x | y | concat(x, y) |
* | ------- | ------- | ------------------ |
* | none | none | none |
* | some(a) | none | none |
* | none | some(a) | none |
* | some(a) | some(b) | some(concat(a, b)) |
*
* @example
* import { getApplySemigroup, some, none } from 'fp-ts/lib/Option'
* import { semigroupSum } from 'fp-ts/lib/Semigroup'
*
* const S = getApplySemigroup(semigroupSum)
* assert.deepStrictEqual(S.concat(none, none), none)
* assert.deepStrictEqual(S.concat(some(1), none), none)
* assert.deepStrictEqual(S.concat(none, some(1)), none)
* assert.deepStrictEqual(S.concat(some(1), some(2)), some(3))
*
* @since 2.0.0
*/
export declare function getApplySemigroup<A>(S: Semigroup<A>): Semigroup<Option<A>>;
/**
* @since 2.0.0
*/
export declare function getApplyMonoid<A>(M: Monoid<A>): Monoid<Option<A>>;
/**
* Monoid returning the left-most non-`None` value
*
* | x | y | concat(x, y) |
* | ------- | ------- | ------------ |
* | none | none | none |
* | some(a) | none | some(a) |
* | none | some(a) | some(a) |
* | some(a) | some(b) | some(a) |
*
* @example
* import { getFirstMonoid, some, none } from 'fp-ts/lib/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(1)), some(1))
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(1))
*
* @since 2.0.0
*/
export declare function getFirstMonoid<A = never>(): Monoid<Option<A>>;
/**
* Monoid returning the right-most non-`None` value
*
* | x | y | concat(x, y) |
* | ------- | ------- | ------------ |
* | none | none | none |
* | some(a) | none | some(a) |
* | none | some(a) | some(a) |
* | some(a) | some(b) | some(b) |
*
* @example
* import { getLastMonoid, some, none } from 'fp-ts/lib/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(1)), some(1))
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(2))
*
* @since 2.0.0
*/
export declare function getLastMonoid<A = never>(): Monoid<Option<A>>;
/**
* Monoid returning the left-most non-`None` value. If both operands are `Some`s then the inner values are
* appended using the provided `Semigroup`
*
* | x | y | concat(x, y) |
* | ------- | ------- | ------------------ |
* | none | none | none |
* | some(a) | none | some(a) |
* | none | some(a) | some(a) |
* | some(a) | some(b) | some(concat(a, b)) |
*
* @example
* import { getMonoid, some, none } from 'fp-ts/lib/Option'
* import { semigroupSum } from 'fp-ts/lib/Semigroup'
*
* 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))
*
* @since 2.0.0
*/
export declare function getMonoid<A>(S: Semigroup<A>): Monoid<Option<A>>;
/**
* @since 2.0.0
*/
export declare const option: Monad1<URI> & Foldable1<URI> & Traversable1<URI> & Alternative1<URI> & Extend1<URI> & Compactable1<URI> & Filterable1<URI> & Witherable1<URI> & MonadThrow1<URI>;
declare const alt: <A>(that: () => Option<A>) => (fa: Option<A>) => Option<A>, ap: <A>(fa: Option<A>) => <B>(fab: Option<(a: A) => B>) => Option<B>, apFirst: <B>(fb: Option<B>) => <A>(fa: Option<A>) => Option<A>, apSecond: <B>(fb: Option<B>) => <A>(fa: Option<A>) => Option<B>, chain: <A, B>(f: (a: A) => Option<B>) => (ma: Option<A>) => Option<B>, chainFirst: <A, B>(f: (a: A) => Option<B>) => (ma: Option<A>) => Option<A>, duplicate: <A>(ma: Option<A>) => Option<Option<A>>, extend: <A, B>(f: (fa: Option<A>) => B) => (ma: Option<A>) => Option<B>, filter: {
<A, B extends A>(refinement: Refinement<A, B>): (fa: Option<A>) => Option<B>;
<A_1>(predicate: Predicate<A_1>): (fa: Option<A_1>) => Option<A_1>;
}, filterMap: <A, B>(f: (a: A) => Option<B>) => (fa: Option<A>) => Option<B>, flatten: <A>(mma: Option<Option<A>>) => Option<A>, foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: Option<A>) => M, map: <A, B>(f: (a: A) => B) => (fa: Option<A>) => Option<B>, partition: {
<A, B extends A>(refinement: Refinement<A, B>): (fa: Option<A>) => Separated<Option<A>, Option<B>>;
<A_1>(predicate: Predicate<A_1>): (fa: Option<A_1>) => Separated<Option<A_1>, Option<A_1>>;
}, partitionMap: <A, B, C>(f: (a: A) => Either<B, C>) => (fa: Option<A>) => Separated<Option<B>, Option<C>>, reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: Option<A>) => B, reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: Option<A>) => B, compact: <A>(fa: Option<Option<A>>) => Option<A>, separate: <A, B>(fa: Option<Either<A, B>>) => Separated<Option<A>, Option<B>>, fromEither: <E, A>(ma: Either<E, A>) => Option<A>;
export {
/**
* @since 2.0.0
*/
alt,
/**
* @since 2.0.0
*/
ap,
/**
* @since 2.0.0
*/
apFirst,
/**
* @since 2.0.0
*/
apSecond,
/**
* @since 2.0.0
*/
chain,
/**
* @since 2.0.0
*/
chainFirst,
/**
* @since 2.0.0
*/
duplicate,
/**
* @since 2.0.0
*/
extend,
/**
* @since 2.0.0
*/
filter,
/**
* @since 2.0.0
*/
filterMap,
/**
* @since 2.0.0
*/
flatten,
/**
* @since 2.0.0
*/
foldMap,
/**
* @since 2.0.0
*/
map,
/**
* @since 2.0.0
*/
partition,
/**
* @since 2.0.0
*/
partitionMap,
/**
* @since 2.0.0
*/
reduce,
/**
* @since 2.0.0
*/
reduceRight,
/**
* @since 2.0.0
*/
compact,
/**
* @since 2.0.0
*/
separate,
/**
* @since 2.0.0
*/
fromEither };
Выполнить команду
Для локальной разработки. Не используйте в интернете!