since import { Alternative1 } from 'fp-ts/lib/Alternative' ; import { Applicative1 } from 'fp-ts/lib/Applicative' ; import { Apply1 } from 'fp-ts/lib/Apply' ; import { Separated , Compactable1 } from 'fp-ts/lib/Compactable' ; import { Either } from 'fp-ts/lib/Either' ; import { Filterable1 , getFilterableComposition } from 'fp-ts/lib/Filterable' ; import { identity , Lazy , Predicate , Refinement } from 'fp-ts/lib/function' ; import { Functor1 } from 'fp-ts/lib/Functor' ; import { Monad1 } from 'fp-ts/lib/Monad' ; import * as O from 'fp-ts/lib/Option' ; import { getOptionM } from 'fp-ts/lib/OptionT' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { task , of as taskOf , map as taskMap , Task } from 'fp-ts/lib/Task' ; import { TaskEither } from 'fp-ts/lib/TaskEither' ; const F = getFilterableComposition ( task , O . option ) ; const T = getOptionM ( task ) ; category since export interface TaskOption < A > extends Task < O . Option < A > > { } category since export const none = T . none ( ) ; category since export const some = T . of ; category since export const fromOption = taskOf ; category since export const fromOptionK = ( f ) => ( ... a ) => fromOption ( f ( ... a ) ) ; category since export const fromTask = T . fromM ; category since export const fromNullable = ( a ) => fromOption ( O . fromNullable ( a ) ) ; category since export const fromTaskEither = ( ma ) => task . map ( ma , O . fromEither ) ; category since export const tryCatch = ( f ) => ( ) => f ( ) . then ( ( a ) => O . some ( a ) , ( ) => O . none ) ; category since export const fold = ( onNone , onSome ) => ( as ) => T . fold ( as , onNone , onSome ) ; category since export const getOrElse = ( onNone ) => ( as ) => T . getOrElse ( as , onNone ) ; category since export const toUndefined = ( ma ) => task . map ( ma , O . toUndefined ) ; category since export const toNullable = ( ma ) => task . map ( ma , O . toNullable ) ; category since export const mapNullable = ( f ) => taskMap ( O . mapNullable ( f ) ) ; category since export const map = ( f ) => ( fa ) => T . map ( fa , f ) ; category since export const ap = ( fa ) => ( fab ) => T . ap ( fab , fa ) ; category since export const apFirst = < B > ( fb ) => < A > ( fa ) : TaskOption < A > => pipe ( fa , map ( ( a ) => ( _ ) => a ) , ap ( fb ) ) ; category since export const apSecond = < B > ( fb ) => < A > ( fa ) : TaskOption < B > => pipe ( fa , map ( ( ) => ( b ) => b ) , ap ( fb ) ) ; category since export const of = some ; category since export const chain = ( f ) => ( ma ) => T . chain ( ma , f ) ; category since export const chainFirst = ( f ) => ( ma ) => T . chain ( ma , ( a ) => T . map ( f ( a ) , ( ) => a ) ) ; category since export const chainTask = ( f ) => ( ma ) => T . chain ( ma , ( a ) => fromTask ( f ( a ) ) ) ; category since export const chainOption = ( f ) => taskMap ( O . chain ( f ) ) ; category since export const chainOptionK = ( f ) => chain ( fromOptionK ( f ) ) ; category since export const flatten = ( mma ) => T . chain ( mma , identity ) ; category since export const alt = ( that ) => ( fa ) => T . alt ( fa , that ) ; category since export const zero = T . none ; category since export const compact = F . compact ; category since export const separate = F . separate ; category since export const filter = < A > ( predicate ) => ( fa ) : TaskOption < A > => F . filter ( fa , predicate ) ; category since export const filterMap = ( f ) => ( fa ) => F . filterMap ( fa , f ) ; category since export const partition = < A > ( predicate ) => ( fa ) : Separated < TaskOption < A > , TaskOption < A > > => F . partition ( fa , predicate ) ; category since export const partitionMap = ( f ) => ( fa ) => F . partitionMap ( fa , f ) ; category since const URI = 'TaskOption' ; category since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { interface URItoKind < A > { TaskOption : TaskOption < A > ; } } category since export const Functor = { URI , map : T . map } ; category since export const Applicative = { URI , map : T . map , ap : T . ap , of } ; category since export const Apply = { URI , map : T . map , ap : T . ap } ; category since export const Monad = { URI , map : T . map , ap : T . ap , chain : T . chain , of } ; category since export const Alternative = { URI , map : T . map , ap : T . ap , alt : T . alt , of , zero } ; category since export const Compactable = { URI , compact , separate } ; category since export const Filterable = { URI , map : T . map , compact : F . compact , filter : F . filter , filterMap : F . filterMap , separate : F . separate , partition : F . partition , partitionMap : F . partitionMap } ; category since export const taskOption = { URI , of : some , ap : T . ap , chain : T . chain , alt : T . alt , zero : T . none , ... getFilterableComposition ( task , O . option ) } ;