by sbjs · 8y ago · 0 comments
Why not have one position-independent version? Something where you can specify at every level which position you want to use, like this:
(~>>> #"foobar"
(~> bytes-length)
(~>> number->string 16)
(~> string->bytes/utf-8))
But that still only limits you to first and last position. Why not use a positional special form like JavaScript has with __dirname called __var? (~>>> #"foobar"
(__var bytes-length)
(number->string 16 __var)
(__var string->bytes/utf-8))
This way you can use it no matter what functions you want. But I don't write my code in Racket so maybe this is already a solved problem.But the first/last variants, -> and ->>, are still useful because they fit a subtle design decision in Clojure. Fns that operate on objects/scalars tend to have the object modified as the very first parameter, while collection-operating fns tend to have the collection last.
[0]https://stuartsierra.com/2018/07/15/clojure-donts-thread-as
[1] https://docs.racket-lang.org/threading/index.html#%28form._%...