/** * `IOOption` represents a synchronous computation that either yields a value of type `A` or nothing. * * If you want to represent a synchronous computation that never fails, please see `IO`. * If you want to represent a synchronous computation that may fail, please see `IOEither`. * * @since 2.12.0 */ import { Alt1 } from './Alt' import { Alternative1 } from './Alternative' import { Applicative1 } from './Applicative' import { Apply1 } from './Apply' import * as chainable from './Chain' import { Compactable1 } from './Compactable' import { Either } from './Either' import { Filterable1 } from './Filterable' import { FromEither1 } from './FromEither' import { FromIO1 } from './FromIO' import { LazyArg } from './function' import { Functor1 } from './Functor' import * as I from './IO' import { IOEither } from './IOEither' import { Monad1 } from './Monad' import { MonadIO1 } from './MonadIO' import * as O from './Option' import { Pointed1 } from './Pointed' import { Predicate } from './Predicate' import { ReadonlyNonEmptyArray } from './ReadonlyNonEmptyArray' import { Refinement } from './Refinement' import { Separated } from './Separated' import { Zero1 } from './Zero' import IO = I.IO import Option = O.Option /** * @category model * @since 2.12.0 */ export interface IOOption extends IO> {} /** * @category constructors * @since 2.12.0 */ export declare const some: (a: A) => IOOption /** * @category lifting * @since 2.12.0 */ export declare const fromPredicate: { (refinement: Refinement): (a: A) => IOOption (predicate: Predicate): (b: B) => IOOption (predicate: Predicate): (a: A) => IOOption } /** * @category conversions * @since 2.12.0 */ export declare const fromOption: (fa: Option) => IOOption /** * @category conversions * @since 2.12.0 */ export declare const fromEither: (fa: Either) => IOOption /** * @category conversions * @since 2.12.0 */ export declare const fromIO: (fa: IO) => IOOption /** * @category conversions * @since 2.12.0 */ export declare const fromIOEither: (fa: IOEither) => IOOption /** * @category pattern matching * @since 2.12.0 */ export declare const match: (onNone: () => B, onSome: (a: A) => B) => (ma: IOOption) => IO /** * Less strict version of [`match`](#match). * * The `W` suffix (short for **W**idening) means that the handler return types will be merged. * * @category pattern matching * @since 2.12.0 */ export declare const matchW: (onNone: () => B, onSome: (a: A) => C) => (ma: IOOption) => IO /** * The `E` suffix (short for **E**ffect) means that the handlers return an effect (`IO`). * * @category pattern matching * @since 2.12.0 */ export declare const matchE: (onNone: () => IO, onSome: (a: A) => IO) => (ma: IOOption) => IO /** * Alias of [`matchE`](#matche). * * @category pattern matching * @since 2.12.0 */ export declare const fold: (onNone: () => I.IO, onSome: (a: A) => I.IO) => (ma: IOOption) => I.IO /** * Less strict version of [`matchE`](#matche). * * The `W` suffix (short for **W**idening) means that the handler return types will be merged. * * @category pattern matching * @since 2.12.0 */ export declare const matchEW: (onNone: () => IO, onSome: (a: A) => IO) => (ma: IOOption) => IO /** * @category error handling * @since 2.12.0 */ export declare const getOrElse: (onNone: LazyArg>) => (fa: IOOption) => IO /** * Less strict version of [`getOrElse`](#getorelse). * * The `W` suffix (short for **W**idening) means that the handler return type will be merged. * * @category error handling * @since 2.12.0 */ export declare const getOrElseW: (onNone: LazyArg>) => (ma: IOOption) => IO /** * @category conversions * @since 2.12.0 */ export declare const toUndefined: (ma: IOOption) => IO /** * @category conversions * @since 2.12.0 */ export declare const toNullable: (ma: IOOption) => IO /** * @category conversions * @since 2.12.0 */ export declare const fromNullable: (a: A) => IOOption> /** * @category lifting * @since 2.12.0 */ export declare const fromNullableK: , B>( f: (...a: A) => B | null | undefined ) => (...a: A) => IOOption> /** * Alias of `flatMapNullable`. * * @category legacy * @since 2.12.0 */ export declare const chainNullableK: ( f: (a: A) => B | null | undefined ) => (ma: IOOption) => IOOption> /** * @category lifting * @since 2.12.0 */ export declare const fromOptionK: , B>( f: (...a: A) => Option ) => (...a: A) => IOOption /** * `map` can be used to turn functions `(a: A) => B` into functions `(fa: F) => F` whose argument and return types * use the type constructor `F` to represent some computational context. * * @category mapping * @since 2.12.0 */ export declare const map: (f: (a: A) => B) => (fa: IOOption) => IOOption /** * @since 2.12.0 */ export declare const ap: (fa: IOOption) => (fab: IOOption<(a: A) => B>) => IOOption /** * @category constructors * @since 2.12.0 */ export declare const of: (a: A) => IOOption /** * @category sequencing * @since 2.14.0 */ export declare const flatMap: { (f: (a: A) => IOOption): (ma: IOOption) => IOOption (ma: IOOption, f: (a: A) => IOOption): IOOption } /** * @category sequencing * @since 2.12.0 */ export declare const flatten: (mma: IOOption>) => IOOption /** * @category error handling * @since 2.12.0 */ export declare const alt: (second: LazyArg>) => (first: IOOption) => IOOption /** * Less strict version of [`alt`](#alt). * * The `W` suffix (short for **W**idening) means that the return types will be merged. * * @category error handling * @since 2.12.0 */ export declare const altW: (second: LazyArg>) => (first: IOOption) => IOOption /** * @since 2.12.0 */ export declare const zero: () => IOOption /** * @category constructors * @since 2.12.0 */ export declare const none: IOOption /** * @category filtering * @since 2.12.0 */ export declare const compact: Compactable1['compact'] /** * @category filtering * @since 2.12.0 */ export declare const separate: Compactable1['separate'] /** * @category filtering * @since 2.12.0 */ export declare const filter: { (refinement: Refinement): (fb: IOOption) => IOOption (predicate: Predicate): (fb: IOOption) => IOOption (predicate: Predicate): (fa: IOOption) => IOOption } /** * @category filtering * @since 2.12.0 */ export declare const filterMap: (f: (a: A) => Option) => (fga: IOOption) => IOOption /** * @category filtering * @since 2.12.0 */ export declare const partition: { (refinement: Refinement): (fb: IOOption) => Separated, IOOption> (predicate: Predicate): (fb: IOOption) => Separated, IOOption> (predicate: Predicate): (fa: IOOption) => Separated, IOOption> } /** * @category filtering * @since 2.12.0 */ export declare const partitionMap: ( f: (a: A) => Either ) => (fa: IOOption) => Separated, IOOption> /** * @category type lambdas * @since 2.12.0 */ export declare const URI = 'IOOption' /** * @category type lambdas * @since 2.12.0 */ export type URI = typeof URI declare module './HKT' { interface URItoKind { readonly [URI]: IOOption } } /** * @category instances * @since 2.12.0 */ export declare const Functor: Functor1 /** * Maps the `Some` value of this `IOOption` to the specified constant value. * * @category mapping * @since 2.16.0 */ export declare const as: { (a: A): <_>(self: IOOption<_>) => IOOption <_, A>(self: IOOption<_>, a: A): IOOption } /** * Maps the `Some` value of this `IOOption` to the void constant value. * * @category mapping * @since 2.16.0 */ export declare const asUnit: <_>(self: IOOption<_>) => IOOption /** * @category mapping * @since 2.12.0 */ export declare const flap: (a: A) => (fab: IOOption<(a: A) => B>) => IOOption /** * @category instances * @since 2.12.0 */ export declare const Pointed: Pointed1 /** * @category instances * @since 2.12.0 */ export declare const Apply: Apply1 /** * Combine two effectful actions, keeping only the result of the first. * * @since 2.12.0 */ export declare const apFirst: (second: IOOption) => (first: IOOption) => IOOption /** * Combine two effectful actions, keeping only the result of the second. * * @since 2.12.0 */ export declare const apSecond: (second: IOOption) => (first: IOOption) => IOOption /** * @category instances * @since 2.12.0 */ export declare const Applicative: Applicative1 /** * @category instances * @since 2.12.0 */ export declare const Chain: chainable.Chain1 /** * @category instances * @since 2.12.0 */ export declare const FromEither: FromEither1 /** * @category instances * @since 2.12.0 */ export declare const FromIO: FromIO1 /** * Composes computations in sequence, using the return value of one computation to determine the next computation and * keeping only the result of the first. * * @category combinators * @since 2.15.0 */ export declare const tap: { (self: IOOption, f: (a: A) => IOOption<_>): IOOption (f: (a: A) => IOOption<_>): (self: IOOption) => IOOption } /** * Composes computations in sequence, using the return value of one computation to determine the next computation and * keeping only the result of the first. * * @example * import { pipe } from 'fp-ts/function' * import * as IOO from 'fp-ts/IOOption' * import * as O from 'fp-ts/Option' * import * as E from 'fp-ts/Either' * * const compute = (value: number) => pipe( * IOO.of(value), * IOO.tapEither((value) => value > 0 ? E.right('ok') : E.left('error')), * ) * * assert.deepStrictEqual(compute(1)(), O.of(1)) * assert.deepStrictEqual(compute(-1)(), O.none) * * @category combinators * @since 2.16.0 */ export declare const tapEither: { (f: (a: A) => Either): (self: IOOption) => IOOption (self: IOOption, f: (a: A) => Either): IOOption } /** * Composes computations in sequence, using the return value of one computation to determine the next computation and * keeping only the result of the first. * * @example * import { pipe } from 'fp-ts/function' * import * as IOO from 'fp-ts/IOOption' * import * as O from 'fp-ts/Option' * import * as Console from 'fp-ts/Console' * * // Will produce `Hello, fp-ts` to the stdout * const effectA = pipe( * IOO.of('fp-ts'), * IOO.tapIO((value) => Console.log(`Hello, ${value}`)), * ) * * // No output to the stdout * const effectB = pipe( * IOO.none as IOO.IOOption, * IOO.tapIO((value) => Console.log(`Hello, ${value}`)), * ) * * async function test() { * assert.deepStrictEqual(effectA(), O.of('fp-ts')) * assert.deepStrictEqual(effectB(), O.none) * } * * test() * * @category combinators * @since 2.16.0 */ export declare const tapIO: { (f: (a: A) => IO<_>): (self: IOOption) => IOOption (self: IOOption, f: (a: A) => IO<_>): IOOption } /** * @category instances * @since 2.12.0 */ export declare const Alt: Alt1 /** * @category instances * @since 2.12.0 */ export declare const Zero: Zero1 /** * @category do notation * @since 2.12.0 */ export declare const guard: (b: boolean) => IOOption /** * @category instances * @since 2.12.0 */ export declare const Alternative: Alternative1 /** * @category instances * @since 2.12.0 */ export declare const Monad: Monad1 /** * @category instances * @since 2.12.0 */ export declare const MonadIO: MonadIO1 /** * @category instances * @since 2.12.0 */ export declare const Compactable: Compactable1 /** * @category instances * @since 2.12.0 */ export declare const Filterable: Filterable1 /** * @category sequencing * @since 2.16.0 */ export declare const flatMapIO: { (f: (a: A) => IO): (self: IOOption) => IOOption (self: IOOption, f: (a: A) => IO): IOOption } /** * @category sequencing * @since 2.16.0 */ export declare const flatMapOption: { (f: (a: A) => Option): (self: IOOption) => IOOption (self: IOOption, f: (a: A) => Option): IOOption } /** * @category sequencing * @since 2.16.0 */ export declare const flatMapEither: { (f: (a: A) => Either<_, B>): (self: IOOption) => IOOption (self: IOOption, f: (a: A) => Either<_, B>): IOOption } /** * @category sequencing * @since 2.16.0 */ export declare const flatMapNullable: { (f: (a: A) => B | null | undefined): (self: IOOption) => IOOption (self: IOOption, f: (a: A) => B | null | undefined): IOOption } /** * @category lifting * @since 2.12.0 */ export declare const fromIOK: , B>(f: (...a: A) => I.IO) => (...a: A) => IOOption /** * Alias of `flatMapIO`. * * @category legacy * @since 2.12.0 */ export declare const chainIOK: (f: (a: A) => I.IO) => (first: IOOption) => IOOption /** * Alias of `tapIO`. * * @category legacy * @since 2.12.0 */ export declare const chainFirstIOK: (f: (a: A) => I.IO) => (first: IOOption) => IOOption /** * @category lifting * @since 2.12.0 */ export declare const fromEitherK: , B>( f: (...a: A) => Either ) => (...a: A) => IOOption /** * Alias of `flatMapEither`. * * @category legacy * @since 2.12.0 */ export declare const chainEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption /** * Alias of `tapEither`. * * @category legacy * @since 2.12.0 */ export declare const chainFirstEitherK: (f: (a: A) => Either) => (ma: IOOption) => IOOption /** * Alias of `flatMapOption`. * * @category legacy * @since 2.12.0 */ export declare const chainOptionK: (f: (a: A) => Option) => (ma: IOOption) => IOOption /** * @category do notation * @since 2.12.0 */ export declare const Do: IOOption<{}> /** * @category do notation * @since 2.12.0 */ export declare const bindTo: (name: N) => (fa: IOOption) => IOOption<{ readonly [K in N]: A }> declare const let_: ( name: Exclude, f: (a: A) => B ) => (fa: IOOption) => IOOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }> export { /** * @category do notation * @since 2.13.0 */ let_ as let } /** * @category do notation * @since 2.12.0 */ export declare const bind: ( name: Exclude, f: (a: A) => IOOption ) => (ma: IOOption) => IOOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }> /** * @category do notation * @since 2.12.0 */ export declare const apS: ( name: Exclude, fb: IOOption ) => (fa: IOOption) => IOOption<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B }> /** * @since 2.12.0 */ export declare const ApT: IOOption /** * Equivalent to `ReadonlyNonEmptyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.12.0 */ export declare const traverseReadonlyNonEmptyArrayWithIndex: ( f: (index: number, a: A) => IOOption ) => (as: ReadonlyNonEmptyArray) => IOOption> /** * Equivalent to `ReadonlyArray#traverseWithIndex(Applicative)`. * * @category traversing * @since 2.12.0 */ export declare const traverseReadonlyArrayWithIndex: ( f: (index: number, a: A) => IOOption ) => (as: readonly A[]) => IOOption /** * Alias of `flatMap`. * * @category legacy * @since 2.12.0 */ export declare const chain: (f: (a: A) => IOOption) => (ma: IOOption) => IOOption /** * Alias of `tap`. * * @category legacy * @since 2.12.0 */ export declare const chainFirst: (f: (a: A) => IOOption) => (first: IOOption) => IOOption