Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Last active September 8, 2025 20:58
Show Gist options
  • Save shaunlebron/623c1c10a3ec81b23bc9fff9abee7840 to your computer and use it in GitHub Desktop.
Save shaunlebron/623c1c10a3ec81b23bc9fff9abee7840 to your computer and use it in GitHub Desktop.

Poor man’s JS Pipe operator

Idea from Timur Xazamov https://x.com/nanot1m/status/1720494020651020562

Summary

While waiting for the JS pipe operator |>, maybe we can use ($=…, $=…, $) instead.

Either locally declare let $; or treat $ as a shared global volatile var:

const foo = (
  $= 2,
  $= bar($),
  $= $.hello.world(),
  $= await fetch($),
  await $.json()
)

Examples

Translating the official examples to this pattern:

Pipeline Equivalent
Object.keys(envars)
  .map(envar => `${envar}=${envars[envar]}`)
  .join(' ')
  |> `$ ${%}`
  |> chalk.dim(%, 'node', args.join(' '))
  |> console.log(%);
$= Object.keys(envars)
     .map(envar => `${envar}=${envars[envar]}`)
     .join(' ')
$= `$ ${$}`
$= chalk.dim($, 'node', args.join(' '))
console.log($)
const envVarFormat = vars =>
  Object.keys(vars)
    .map(var => `${var}=${vars[var]}`)
    .join(' ')
    |> chalk.dim(%, 'node', args.join(' '));
const envVarFormat = vars => (
  $= Object.keys(vars)
    .map(var => `${var}=${vars[var]}`)
    .join(' '),
  chalk.dim($, 'node', args.join(' '))
)
return (
  <ul>
    {
      values
        |> Object.keys(%)
        |> [...Array.from(new Set(%))]
        |> %.map(envar => (
          <li onClick={
            () => doStuff(values)
          }>{envar}</li>
        ))
    }
  </ul>
);
return (
  <ul>
    {(
      $= values,
      $= Object.keys($),
      $= [...Array.from(new Set($))],
      $.map(envar => (
        <li onClick={
          () => doStuff(values)
        }>{envar}</li>
      ))
    )}
  </ul>
);
const x = foo()
  |> bar(%)
  |> () => log(%) // closure
  |> baz(%)
  |> done(%)
const x = (
  $= foo(),
  $= bar($),
  $= ($$=>
        () => log($$)
     )($),
  $= baz($),
  done($)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment