diff --git a/CHANGELOG.md b/CHANGELOG.md index aa708b5c1..f46fbe48c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - **Bug Fix** - fixed EitherT to only run code on the left once, closes #219 (@nfma) + - fixed OptionT to only run code on none once (@gcanti) # 0.5.1 diff --git a/src/OptionT.ts b/src/OptionT.ts index c1d5ee377..d2a3330f8 100644 --- a/src/OptionT.ts +++ b/src/OptionT.ts @@ -1,7 +1,6 @@ import { HKT, HKTS, HKT2S, HKTAs, HKT2As } from './HKT' import { Functor } from './Functor' import { Monad } from './Monad' -import { Chain } from './Chain' import { Applicative, getApplicativeComposition, @@ -26,11 +25,11 @@ export interface OptionT2 extends ApplicativeComposition21(F: Chain): OptionT2['chain'] - chain(F: Chain): OptionT1['chain'] - chain(F: Chain): OptionT['chain'] - chain(F: Chain): OptionT['chain'] { - return (f, fa) => F.chain(o => o.fold(() => fa as any, a => f(a)), fa) + chain(F: Monad): OptionT2['chain'] + chain(F: Monad): OptionT1['chain'] + chain(F: Monad): OptionT['chain'] + chain(F: Monad): OptionT['chain'] { + return (f, fa) => F.chain(o => o.fold(() => F.of(option.none), a => f(a)), fa) } some(F: Applicative): (a: A) => HKT2As>