Skip to content

Commit

Permalink
fix Some.reduce so it calls f (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
leemhenson authored and gcanti committed Apr 26, 2017
1 parent 9341749 commit 8c66487
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StaticExtend, FantasyExtend } from './Extend'
import { StaticSetoid } from './Setoid'
import { StaticTraversable, FantasyTraversable } from './Traversable'
import { StaticAlternative, FantasyAlternative } from './Alternative'
import { identity, constant, constFalse, constTrue, Lazy, Predicate } from './function'
import { constant, constFalse, constTrue, Lazy, Predicate } from './function'

declare module './HKT' {
interface HKT<A> {
Expand Down Expand Up @@ -131,7 +131,7 @@ export class Some<A> implements
return f(this.value)
}
reduce<B>(f: (b: B, a: A) => B, b: B): B {
return this.fold<B>(constant(b), identity)
return this.fold<B>(constant(b), (a: A) => f(b, a))
}
traverse<F extends HKT2S>(applicative: StaticApplicative<F>): <L, B>(f: (a: A) => HKT2<L, B>[F]) => HKT2<L, Option<B>>[F]
traverse<F extends HKTS>(applicative: StaticApplicative<F>): <B>(f: (a: A) => HKT<B>[F]) => HKT<Option<B>>[F]
Expand Down
6 changes: 6 additions & 0 deletions test/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ describe('Option', () => {
eq(y, some(some(5)))
})

it('reduce', () => {
const x = fromNullable(null).reduce((b, a) => 1, 2)
assert.strictEqual(x, 2)
const y = fromNullable(3).reduce((b, a) => a.toString(), '4')
assert.strictEqual(y, '3')
})
})

0 comments on commit 8c66487

Please sign in to comment.