Skip to content

Instantly share code, notes, and snippets.

pipe(
value => value, // Identity
value => Promise.resolve(value), // Promise wrapped identity
value -> 2 * value, // multiplyBy2
async value => 2 * value // asyncMultiplyBy2
function pipe (...fns) {
return input => fns.reduce(async (previousOutput, fn) => fn(await previousOutput), input)
}
{
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'
function pipe (...fns) {
return input => fns.reduce((previousOutput, fn) => fn(previousOutput), input)
}
{
const actual = pipe(identity, identity, identity)(1)
const expected = 1
const msg = 'passing identity n times should return unmodified value'
deepEqual(actual, expected, msg)
}
module.exports = {
pipe
}
function pipe (fn) {
return value => fn(value)
}
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()
})
app.get('/stores', (req, res) => {
const responseBody = pipe(
composeRequest
makeRequest,
composeResponse
)(req.body)
res.json(responseBody)
})
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'))
})
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}`))