Software Engineer @ ClickFox
Hack Reactor Remote
Educator
Skateboarder
Music stuff
Everything that is presented may change tomorrow. Or next week. Or never.
|>
--enable-pipeline-operator
Minimal Proposal Syntax
|>
expression |> function
input |> f1 |> f2 |> f... |> fn
fn(f...(f2(f1(input)))
const add = (x, y) => x + y
10 |> ( _ => add(5, _) )
Minimal Proposal Syntax Example
const doubleSay = (str) => str + ", " + str;
const capitalize = (str) => str[0].toUpperCase() + str.substring(1);
const exclaim = (str) => str + '!';
let res = "hello" |> doubleSay |> capitalize |> exclaim
let res = exclaim(capitalize(doubleSay("hello")))
console.log(res) // "Hello, hello!"
Minimal Proposal Limitations
No support for async-await functions
Will throw an error
Competing Proposals
x |> f //--> f(x)
x |> f(y) //--> f(y)(x)
x |> (a => f(a,10)) //--> f(x,10)
// Async Solution
x |> f |> await //--> await f(x)
x |> f |> await |> g //--> g(await f(x))
Competing Proposals
x |> f(#) //--> f(x) x |> f(y)(#) //--> f(y)(x) x |> f //--> Syntax Error x |> f(#,10) //--> f(x,10) // Async Solution x |> await f(#) //--> await f(x) x |> await f(#) |> g(#) //--> g(await f(x)) [Note: # is not the exact symbol for the temporary scoped binding]
Competing Proposals
Stage 1 proposal
add.bind(null, 1)
const addOne = add(1, ?); // apply from the left
addOne(2); // 3
const addTen = add(?, 10); // apply from the right
addTen(2); // 12
x |> add(1, ?)
where x is applied as second argument to add
const player = { score: 44 }; let newScore = player.score |> add(8, ?) |> divide(?, 2) |> multiply(?, 3) |> subtract(?, 23) |> (x => Math.max(0, Math.min(?, 100))) console.log(newScore) // 55
Pipeline Operator
FireFox v58+ Flag :: --enable-pipeline-operator
Babel Plugin :: @babel/plugin-proposal-pipeline-operator
James-H33 :: Pipeline Operator Repo
Partial Application Syntax
citycide :: param.macro Repo
My opinion?