4 ms·
I feel languages should just have some kind of sugar or operator for this, in fact in Ocaml the |> operator exists where <exp> |> <exp2> <exp2>(<exp>) A
by Blikkentrekker 4mo ago
I feel languages should just have some kind of sugar or operator for this, in fact in Ocaml the |> operator exists where
<exp> |> <exp2>
<exp2>(<exp>)
Are just one and the same
For a variadic language you'd need something more involved though. But some kind of syntax can probably be invented in some language.
- emidln 4mo agoIt's common to write the thrush combinator as a lisp macro. Clojure ships ->, ->>, as->, some->, some->>, cond->, and cond->> out of the box. You can find similar macros for CL[0], Racket[1], and a scheme SRFI[2]. Writing them is a fun exercise in your lisp of choice if you don't have a library available. [0] https://github.com/dtenny/clj-arrows https://github.com/dtenny/clj-arrows [1] https://docs.racket-lang.org/threading/index.html https://docs.racket-lang.org/threading/index.html [2] https://srfi.schemers.org/srfi-197/srfi-197.html https://srfi.schemers.org/srfi-197/srfi-197.html
- sph 4mo agoElixir has it. To make it worthwhile, the entire standard library has to be designed to have the ‘object’ of the function as first argument. [1,2,3] |> Enum.map(&square/1) |> Enum.filter(&odd?/1) Using a threading operator where there is no such consistency is painful. This is why I dislike CL’s or Python’s map function, taking the list to operate on as second argument, instead of first. A threading operator wouldn’t be as effective there.
- shawn_w 4mo agoTaking the object as the last argument works just as well. Just needs to be consistent whichever way is chosen.
- Blikkentrekker 4mo agoThe issue is that these functions in Lisps are variadic and can accept more arguments than one. `map`, and `zipwidth` in lisps are actually the same function.