JanetDocsPlaygroundI'm feeling luckyGitHub sign in

->



    macro
    boot.janet on line 1237, column 1

    (-> x & forms)

    Threading macro. Inserts x as the second value in the first form in 
    `forms`, and inserts the modified first form into the second form 
    in the same manner, and so on. Useful for expressing pipelines of 
    data.


See also:->>6 examplesSign in to add an example
Loading...
# wrap short-fn / | 
(-> 10
    (|(/ $ 2)))
# =>
5

# also wrap fn
(-> 10
    ((fn [n] (/ n 2))))
# =>
5
sogaiuPlayground
(-> "X"
    (string "a" "b")
    (string "c" "d")
    (string "e" "f"))  # => "Xabcdef"
uvtcPlayground
(->
  {:a [1 2 3] :b [4 5 6]}
  (get :a)
  (sum)
  (string " is the result"))
# -> "6 is the result"

# same as:
(string (sum (get {:a [1 2 3] :b [4 5 6]} :a))" is the result")
felixrPlayground
(->  1 (< 2))   # -> true
(->> 1 (< 2))   # -> false
cellularmitosisPlayground
(-> 1 (+ 2) (+ 3))  # -> 6
cellularmitosisPlayground
(defn inc [x] (+ x 1))
(defn inv [x] (* x -1))
(defn sq  [x] (* x x))

(-> 2 inc)             # -> 3
(-> 2 inc inc)         # -> 4
(-> 2 inc inc inv)     # -> -4
(-> 2 inc inc inv sq)  # -> 16
cellularmitosisPlayground