TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #3376 3.2K
CHALLENGE

function* pipeline(...fns) {
let value = yield;
for (const fn of fns) {
value = yield fn(value);
}
return value;
}

const double = x => x * 2;
const addTen = x => x + 10;
const square = x => x * x;

const gen = pipeline(double, addTen, square);

gen.next(); // prime the generator
const r1 = gen.next(3);
const r2 = gen.next(r1.value);
const r3 = gen.next(r2.value);

console.log(r1.value, r2.value, r3.value);
  • ❤ 6
  • 👍 2
  • 🔥 1
More from @javascript
  1. Sep 20, 2026Post #3507
  2. Sep 20, 2026CHALLENGE 'use strict'; function getValue() { return this.value; } const obj = { value: 42…
  3. Sep 19, 2026Post #3505
  4. Sep 19, 2026CHALLENGE const a = 5 & 3; const b = 5 | 2; const c = ~5; const d = 1 << 31; const e = -1…
  5. Sep 18, 2026Post #3503
  6. Sep 18, 2026CHALLENGE let i = 0; const key = () => `k${i++}`; const obj = { [key()]: i, [key()]: i, [k…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →