Live data from Hacker News

Pipelining might be my favorite programming language feature

herecomesthemoon.net

121–130 of 360 posts

Re: Pipelining might be my favorite programming language feature

#122
After seeing LangChain abusing the "|" operator overload for pipeline-like DSL, I followed the suite at work and I loved it. It's especially good when you use it in a notebook environment where you literally build the pipeline incrementally through repl.

Re: Pipelining might be my favorite programming language feature

#123
post #45

Earlier quoted context omitted.

Yes, but here's my hot take - what if you didn't have to edit the source code to debug it? Instead of chaining method calls you just assign to a temporary variable. Then you can set breakpoints and inspect variable values like you do normally without editing source. It's not like you lose that much readability from foo(bar(baz(c))) c |> baz |> bar |> foo c.baz().bar().foo() t = c.baz() t = t.bar() t = t.foo()

The Clojure equivalent of `c |> baz |> bar |> foo` are the threading macros: (-> c baz bar foo) But people usually put it on separate lines: (-> c baz bar foo)

And with the Emacs Enlighten feature the second version enables seeing the results of each step right in the editor, to the right of the step.

Re: Pipelining might be my favorite programming language feature

#124
post #66
post #28

Clojure has pipeline functions -> and ->> without resorting to OO dot syntax.

As well as some-> (exit on null) and cond-> (with predicates) that are often handy.

As well as a lot of flexibility on where the result of the previous step feeds into the current one.

Re: Pipelining might be my favorite programming language feature

#125

Earlier quoted context omitted.

Haskell has & which goes the other way: users & map validate & catMaybes & mapM persist

Yes, `&` (reverse apply) is equivalent to `|>`, but it is interesting that there is no common operator for reversed compose `.`, so function compositions are still read right-to-left. In my programming language, I added `.>` as a reverse-compose operator, so pipelines of function compositions can also be read uniformly left-to-right, e.g. process = map validate .> catMaybes .> mapM persist

Elm (written in Haskell) uses |> and > and https://hackage.haskell.org/package/nri-prelude (written by a company that uses a lot of Elm in order to make writing Haskell look more like writing Elm).

There is also https://hackage.haskell.org/package/flow which uses .> and EDIT: in no way do I want to claim the originality of these things in Elm or the Haskell package inspired by it. AFAIK |> came from F# but it could be miles earlier.

Re: Pipelining might be my favorite programming language feature

#126
post #113
post #95

A pipeline operator is just partial application with less power. You should be able to bind any number of arguments to any places in order to create a new function and "pipe" its output(s) to any other number of functions. One day, we'll (re)discover that partial application is actually incredibly useful for writing programs and (non-Haskell) languages will start with it as the primitive for composing programs instea…

... and then recreate the scripting language...

I was just thinking does this not sound like a shell language? Using | instead of .function()

Re: Pipelining might be my favorite programming language feature

#127

Kotlin sort of have it with let (and run) a().let{ b(it) }.let{ c(it) }

Yeah, Kotlin's solution is nice because it's so general: you can chain on to anything instead of needing everyone to implement a builder pattern.

And it's already idiomatic unlike bolting a pipeline operator onto a language that didn't start with it.

Re: Pipelining might be my favorite programming language feature

#129
post #25
post #19

data.iter() .filter(|w| w.alive) .map(|w| w.id) .collect() collect(map(filter(iter(data), |w| w.alive), |w| w.id)) The second approach is open for extension - it allows you to write new functions on old datatypes. > Quick challenge for the curious Rustacean, can you explain why we cannot rewrite the above code like this, even if we import all of the symbols? Probably for lack of > weird operators like , , $, or >>=

Extension methods to the rescue: https://en.wikipedia.org/wiki/Extension_method Examples: https://kotlinlang.org/docs/extensions.html https://docs.scala-lang.org/scala3/reference/contextual/exte... See also: https://en.wikipedia.org/wiki/Uniform_function_call_syntax

Came here for the Uniform function call syntax link. This is one of the little choices that has a big impact on a language! I love it!

I wrote a little pipeline macro in https://nim-lang.org/ for Advent of Code years ago and as far as I know it worked okay.

``` import macros

  macro `|>`\* (left, right : expr): expr =
    result = newNimNode(nnkCall)

    case right.kind
    of nnkCall:
      result.add(right[0])
      result.add(left)
      for i in 1..
```

Makes me want to go write more nim.

Re: Pipelining might be my favorite programming language feature

#130
That new Rhombus language that was featured here recently has an interesting feature where you can use `_` in a function call to act as a "placeholder" for an argument. Essentially it's an easy way to partially apply a function. This works very well with piping because it allows you to pipe into any argument of a function (including optional arguments iirc) rather than just the first like many pipe implementations have. It seems really cool!
Post reply on HN