Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/__tests__/pipeR.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const pipeR = require('../pipeR')

describe('core/pipeR', () => {
test('afd', () => {
const expected = 10
const func = pipeR(next => [
num => num < 10 ? next(num + 1) : num
])

const actual = func(0)
expect(actual).resolves.toBe(expected)
})
})
11 changes: 11 additions & 0 deletions internal/__tests__/curry3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const curry3 = require('../curry3')

describe('internal/curry3', () => {
const add = (x, y, z) => x + y + z

test('curries', () => {
const expected = 6
const actual = curry3(add)(1)(2)(3)
expect(actual).toBe(expected)
})
})
41 changes: 41 additions & 0 deletions internal/__tests__/iterableSerialReduce.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const iterableSerialReduce = require('../iterableSerialReduce')

describe('internal/iterableSerialReduce', () => {
const add = (x, y) => x + y
const asyncAdd = (x, y) => Promise.resolve().then(() => x + y)
function* iterator() {
yield 1
yield 2
yield 3
}

test('sync array', () => {
const expected = 6
const actual = iterableSerialReduce(add, 0, [1, 2, 3])
expect(actual).resolves.toBe(expected)
})

test('sync array 2', () => {
const expected = 6
const actual = iterableSerialReduce(add, null, [2, 3], Promise.resolve(1))
expect(actual).resolves.toBe(expected)
})

test('sync iterator', () => {
const expected = 6
const actual = iterableSerialReduce(add, 0, iterator())
expect(actual).resolves.toBe(expected)
})

test('async array', () => {
const expected = 6
const actual = iterableSerialReduce(asyncAdd, 0, [1, 2, 3])
expect(actual).resolves.toBe(expected)
})

test('async iterator', () => {
const expected = 6
const actual = iterableSerialReduce(asyncAdd, 0, iterator())
expect(actual).resolves.toBe(expected)
})
})
4 changes: 4 additions & 0 deletions internal/curry3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const curry3 = func => a => b => c =>
func (a, b, c)

module.exports = curry3
16 changes: 16 additions & 0 deletions list/__tests__/filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const filter = require("../filter")
describe("list/filter", () => {
const isOdd = num => num % 2 !== 0
const asyncIsOdd = num => Promise.resolve(num).then(isOdd)
const asyncWhenIsOdd = num => isOdd(num) ? true : asyncIsOdd(num)

function* iterator() {
yield 1
yield 2
Expand Down Expand Up @@ -34,4 +36,18 @@ describe("list/filter", () => {
const actual = filter(asyncIsOdd)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})

test("mixed array", () => {
expect.assertions(1)
const expected = [1, 3]
const actual = filter(asyncWhenIsOdd)([1, 2, 3])
return expect(actual).resolves.toMatchObject(expected)
})

test("mixed iterator", () => {
expect.assertions(1)
const expected = [1, 3]
const actual = filter(asyncWhenIsOdd)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})
})
16 changes: 16 additions & 0 deletions list/__tests__/map.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const map = require("../map")

describe("list/map", () => {
const isOdd = num => num % 2 !== 0
const double = num => num * 2
const asyncDouble = num => Promise.resolve(num).then(double)
const asyncWhenOddDouble = num => isOdd(num) ? double(num) : Promise.resolve(num).then(double)
function* iterator() {
yield 1
yield 2
Expand Down Expand Up @@ -36,4 +38,18 @@ describe("list/map", () => {
const actual = map(asyncDouble)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})

test("mixed array", () => {
expect.assertions(1)
const expected = [2, 4, 6]
const actual = map(asyncWhenOddDouble)([1, 2, 3])
return expect(actual).resolves.toMatchObject(expected)
})

test("mixed iterable", () => {
expect.assertions(1)
const expected = [2, 4, 6]
const actual = map(asyncWhenOddDouble)(iterator())
return expect(actual).resolves.toMatchObject(expected)
})
})
2 changes: 1 addition & 1 deletion list/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const filter = func => iterable => {
while (!done) {
const result = func(value)
if (isThenable(result)) {
return iterableSerialReduce(asyncFilterReducer(func), null, iterator, result.then(() => [ value ]))
return iterableSerialReduce(asyncFilterReducer(func), null, iterator, result.then(test => values.concat(test ? value : [])))
}
if (result) {
values.push(value)
Expand Down
2 changes: 1 addition & 1 deletion list/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const map = func => iterable => {
const result = func(value)

if (isThenable(result)) {
return iterableSerialReduce(asyncMapReducer(func), null, iterator, result.then(v => [ v ]))
return iterableSerialReduce(asyncMapReducer(func), null, iterator, result.then(x => values.concat(x)))
}

values.push(result)
Expand Down
9 changes: 9 additions & 0 deletions net/__tests__/axios.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const axios = require('../axios')

describe('net/axios', () => {
test('has functions', () => {
const expected = ['get', 'delete', 'head', 'options', 'post', 'put', 'patch']
const actual = Object.keys(axios)
expect(actual).toMatchObject(expected)
})
})