This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipe( | |
value => value, // Identity | |
value => Promise.resolve(value), // Promise wrapped identity | |
value -> 2 * value, // multiplyBy2 | |
async value => 2 * value // asyncMultiplyBy2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe (...fns) { | |
return input => fns.reduce(async (previousOutput, fn) => fn(await previousOutput), input) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
const actual = pipe(addTwo, identity, multiplyByThree)(1) | |
const expected = 9 | |
const msg = 'passing functions that do simple math operations' | |
deepEqual(actual, expected, msg) | |
} | |
{ | |
const actual = pipe(addTwo, identity, multiplyByThree)(1) | |
const expected = multiplyByThree(identity(addTwo(1))) | |
const msg = 'functions passed should be able to be composed and produce same output' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe (...fns) { | |
return input => fns.reduce((previousOutput, fn) => fn(previousOutput), input) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
const actual = pipe(identity, identity, identity)(1) | |
const expected = 1 | |
const msg = 'passing identity n times should return unmodified value' | |
deepEqual(actual, expected, msg) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
pipe | |
} | |
function pipe (fn) { | |
return value => fn(value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const test = require('tape') | |
test('pipe', function ({ deepEqual, end }) { | |
const identity = value => value | |
const actual = pipe(identity)(1) | |
const expected = 1 | |
const msg = 'passing just identity should return unmodified value' | |
deepEqual(actual, expected, msg) | |
end() | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/stores', (req, res) => { | |
const responseBody = pipe( | |
composeRequest | |
makeRequest, | |
composeResponse | |
)(req.body) | |
res.json(responseBody) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { BeforeAll, AfterAll } = require('cucumber') | |
const spawn = require('child_process').spawn | |
const path = require('path') | |
const processes = [] | |
BeforeAll(async function () { | |
/* start up any process before running any test */ | |
processes.push(await runServer('app')) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const port = process.env.PORT || 3000 | |
app.get('/stores', (req, res) => res.json({ name: 'hello world' })) | |
app.listen(port, () => console.log(`app magic happens on port ${port}`)) |