What does -> do in clojure?

前端 未结 6 1292
既然无缘
既然无缘 2021-02-01 04:02

I have seen the clojure symbol -> used in many places, but I am unsure as to what this symbol is called and does, or even whether it is part of standard clojure. Could someone e

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-01 04:44

    It's a way to write code left to right, instead of inside out, e.g.

    (reduce (map (map xs bar) foo) baz)
    

    becomes

    (-> xs (map bar) (map foo) (reduce baz))
    

    You might want to read the source, it's here.

    EDIT: Fixed my confusion of -> with ->>, thanks to amalloy. Sadly my example is now quite unlikely to appear in practice.

提交回复
热议问题