Skip to content
Prev 393525 / 398503 Next

Pipe operator

This is both true and misleading.
The shell pipe operation came from functional
programming.  In fact the shell pipe operation
is NOT "flip apply", which is what |> is, but
it is functional composition.  That is
<in command = command(in)
command >out = let out = command
cmd1 | cmd2 = \x.cmd2(cmd1(x)).

Pragmatically, the Unix shell pipe operator does
something very important, which |> (and even
functional composition doesn't in F#):
<in cmd1 | cmd2 > out *interleaves* the computation
of cmd1 and cmd2, streaming the data.  But in R,
x |> f() |> g()
is by definition g(f(x)), and if g needs the value
of its argument, the *whole* of f(x) is evaluated
before g resumes.  This is much closer to what the
pipe syntax in the MS-DOS shell did, if I recall
correctly.
On Wed, 4 Jan 2023 at 17:46, Milan Glacier <news at milanglacier.com> wrote: