Skip to content

Commit

Permalink
fix bug in list/map and list/filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
joelnet committed Oct 16, 2018
1 parent a4202f6 commit 3256051
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions list/__tests__/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ describe("list/filter", () => {
const actual = filter(asyncWhenIsOdd)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})

test('filter does not cache', () => {
expect.assertions(1)
const expected = [1, 3]
const filterOdd = filter (isOdd)
filterOdd ([ 1, 2, 3 ])
const actual = filterOdd ([ 1, 2, 3 ])
expect(actual).toEqual(expected)
})
})
9 changes: 9 additions & 0 deletions list/__tests__/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ describe("list/map", () => {
const actual = map(asyncWhenOddDouble)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})

test('map does not cache', () => {
expect.assertions(1)
const expected = [2, 4]
const mapDouble = map (double)
mapDouble ([1, 2])
const actual = mapDouble ([1, 2])
expect(actual).toEqual(expected)
})
})
2 changes: 1 addition & 1 deletion list/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const asyncFilterReducer = func => acc => x =>
call (val => (val && acc.push(x), acc)) (func (x))

// filter :: Function -> Iterable -> Array
const filter = predicate => reduceWhile (null) (asyncFilterReducer (predicate)) ([])
const filter = predicate => iterable => reduceWhile (null) (asyncFilterReducer (predicate)) ([]) (iterable)

module.exports = filter
2 changes: 1 addition & 1 deletion list/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const asyncMapReducer = func => acc => x =>
call (val => (acc.push(val), acc)) (func (x))

// map :: Function -> Iterable -> Array
const map = func => reduceWhile (null) (asyncMapReducer (func)) ([])
const map = func => iterable => reduceWhile (null) (asyncMapReducer (func)) ([]) (iterable)

module.exports = map

0 comments on commit 3256051

Please sign in to comment.