hello is there anything like to move results of a function to next one like ->
of clojure https://clojuredocs.org/clojure.core/-%3E as a sample ;; Arguably a bit cumbersome to read:
user=> (first (.split (.replace (.toUpperCase "a b c d") "A" "X") " "))
"X"
;; Perhaps easier to read:
user=> (-> "a b c d"
.toUpperCase
(.replace "A" "X")
(.split " ")
first)
"X"
See the threading
package.
thnak you
Also the qi package, which offers a lot of similar ideas in addition to threading like macros
I am checking it out now
In many cases, you can just use the function name, but sometimes you’ll need to use _
as a placeholder. For example: (~> "a b c d"
string-upcase
(string-replace _ "A" "X")
string-split
first)
(referring to threading
)
My bad, ~>
threads into the first position, so the _
isn’t necessary above: (~> "a b c d"
string-upcase
(string-replace "A" "X")
string-split
first)
This is basically true of qi’s threading operators, though the syntax for the arguments is slightly different: (~> ("a b c d") …)
This is because qi is multi-valued, so needs a way to delimit arguments being threaded and the functions (flows) being applied.
I’m not familiar with the ->
function. Does that work roughly like F#’s \|>
operator, but made to fit into s-expressions?
Yup