Function composition operators eg
a |> b # Call `b` with `a` as an argument
b <| a # Same as above, reversed direction
Then you can do something like let x : Map = collect <|
[a, b, c]
|> map(entries)
|> flattenFunction composition operators eg
a |> b # Call `b` with `a` as an argument
b <| a # Same as above, reversed direction
Then you can do something like let x : Map = collect <|
[a, b, c]
|> map(entries)
|> flattenIt's very common already: try-with-resource (java), using (C#), bracket (haskell), unwind-protect (common-lisp), ... though it the latter two it's more of a building block.
Also building block: languages with a convenient and "unrestricted" syntax for anonymous function can just use that e.g. Smalltalk, Ruby, ... in Ruby a "with" is usually just passing a block to the corresponding object's constructor:
# python
with open(...) as f:
...
# ruby
File::open(...) do |f|
...
endI prefer RAII.
E.g. https://mmhaskell.com/blog/2021/7/5/function-application-usi...
paint(sand(cut(measure(wood, 12), 40, :WZ), 220), :red)
wood | measure(12) | cut(40, :WZ) | sand(220) | paint(:red)
IIRC you can do that in Haskell as well, but I forget the name of the feature. Many OOP libraries have started to adopt a chained method call style similar to this, but it is nice to be able to do with any function.
wood
& measure 12
& cut 40 WZ
& sand 220
& paint Red
See https://hackage.haskell.org/package/base-4.17.0.0/docs/Data-...It's less of an issue if your language has UFCS or other postfix function call syntax like mentioned in this thread, but if you don't this is nice to have.
For instance Racket and Clojure have threading macros, which are more flexible as they're just macros (Clojure's `->` is equivalent to Elixir's pipe operator, but `->>` will fill in the last parameter rather than first, and `-->` lets you use a keyword to define where the parameter is inserted in each call).
Haskell let anyone who wants define their own pipe operator, historically you had to BYO, which wasn't exactly hard:
(|>) = flip ($)
or x |> f = f x
would do (modulo fixity), but today it's provided by default as "(&)".