2 ms·
Chaining without nesting.
by mikepurvis 4y ago
Chaining without nesting.
- whatshisface 4y agoIf you mean without closing parentheses, I think you can also do that in languages like Haskell with non-parenthetical function calls.
- mikepurvis 4y agoI'm not a Haskell user, but my experience with this in the Nix language is a bit mixed. It definitely works sometimes, but then you get a pileup of parenthesis nesting anyway, because the default is greedy and you have to control which functions get which arguments.
- nine_k 4y agoDon't $ signs work in Nix the way the work in Haskell? E.g. https://mmhaskell.com/blog/2021/7/5/function-application-using-the-dollar-sign- https://mmhaskell.com/blog/2021/7/5/function-application-usi...
- mikepurvis 4y agoIf so, I've never seen that style used or documented.
- pavon 4y agoIt also allows you to invert the order of the calls so they are written in the order they occur. Instead of paint(sand(cut(measure(wood)))), you can write wood | measure | cut | sand | paint, which is easier to read, especially if it splits over multiple lines or has additional arguments: 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.
- wbadart 4y agoIn Haskell, if all the functions in the pipeline are pure, I'd probably write that as wood & measure 12 & cut 40 WZ & sand 220 & paint Red See https://hackage.haskell.org/package/base-4.17.0.0/docs/Data-Function.html#v:-38- https://hackage.haskell.org/package/base-4.17.0.0/docs/Data-...