since import { Alt1 } from 'fp-ts/lib/Alt' ; import { Applicative1 } from 'fp-ts/lib/Applicative' ; import { Apply1 } from 'fp-ts/lib/Apply' ; import { Alternative1 } from 'fp-ts/lib/Alternative' ; import { Separated , Compactable1 } from 'fp-ts/lib/Compactable' ; import { Either } from 'fp-ts/lib/Either' ; import { Functor1 } from 'fp-ts/lib/Functor' ; import * as O from 'fp-ts/lib/Option' ; import { getOptionM } from 'fp-ts/lib/OptionT' ; import { getFilterableComposition , Filterable1 } from 'fp-ts/lib/Filterable' ; import { identity , Predicate , Refinement } from 'fp-ts/lib/function' ; import { getSemigroup as getIOSemigroup , io , of as ioOf , map as ioMap , IO } from 'fp-ts/lib/IO' ; import { IOEither } from 'fp-ts/lib/IOEither' ; import { Monad1 } from 'fp-ts/lib/Monad' ; import { MonadIO1 } from 'fp-ts/lib/MonadIO' ; import { Monoid } from 'fp-ts/lib/Monoid' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { Semigroup } from 'fp-ts/lib/Semigroup' ; import Option = O . Option ; const T = getOptionM ( io ) ; const F = getFilterableComposition ( io , O . option ) ; category since export interface IOOption < A > extends IO < Option < A > > { } category since export const none = T . none ( ) ; category since export const some = T . of ; category since export const fromIO = T . fromM ; category since export const fromOption = ioOf ; category since export const fromOptionK = ( f ) => ( ... a ) => fromOption ( f ( ... a ) ) ; category since export const fromNullable = ( a ) => fromOption ( O . fromNullable ( a ) ) ; category since export const fromIOEither = ( ma ) => io . map ( ma , O . fromEither ) ; category since export const fold = ( onNone , onSome ) => ( ma ) => T . fold ( ma , onNone , onSome ) ; category since export const getOrElse = ( onNone ) => ( ma ) => T . getOrElse ( ma , onNone ) ; category since export const toUndefined = ( ma ) => io . map ( ma , O . toUndefined ) ; category since export const toNullable = ( ma ) => io . map ( ma , O . toNullable ) ; category since export const mapNullable = ( f ) => ioMap ( 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 ) : IOOption < A > => pipe ( fa , map ( ( a ) => ( _ ) => a ) , ap ( fb ) ) ; category since export const apSecond = < B > ( fb ) => < A > ( fa ) : IOOption < 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 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 = ( ) => ( ) => O . none ; category since export const compact = F . compact ; category since export const separate = F . separate ; category since export const filter = < A > ( predicate ) => ( fa ) => F . filter ( fa , predicate ) ; category since export const filterMap = ( f ) => ( fa ) => F . filterMap ( fa , f ) ; category since export const partition = < A > ( predicate ) => ( fa ) => F . partition ( fa , predicate ) ; category since export const partitionMap = ( f ) => ( fa ) => F . partitionMap ( fa , f ) ; category since export const URI = 'IOOption' ; category since export type URI = typeof URI ; declare module 'fp-ts/lib/HKT' { interface URItoKind < A > { IOOption : IOOption < A > ; } } category since export const getApplySemigroup = < A > ( S ) : Semigroup < IOOption < A > > => getIOSemigroup ( O . getApplySemigroup < A > ( S ) ) ; category since export const getApplyMonoid = < A > ( M ) : Monoid < IOOption < A > > => ( { concat : getApplySemigroup < A > ( M ) . concat , empty : some ( M . empty ) } ) ; 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 , of , chain : T . chain } ; category since export const Alt = { URI , map : T . map , alt : T . alt } ; category since export const Alternative = { URI , map : T . map , ap : T . ap , of , alt : T . alt , zero } ; category since export const Compactable = { URI , compact , separate } ; category since export const Filterable = { URI , map : T . map , compact , separate , filter : F . filter , filterMap : F . filterMap , partition : F . partition , partitionMap : F . partitionMap } ; since export const ioOption = { URI , of : some , ap : T . ap , chain : T . chain , alt : T . alt , fromIO , ... F } ;