What does the leading arrow in a name mean in clojure

前端 未结 2 1780
北恋
北恋 2021-02-02 11:42

Learning Clojure I came across code like below:

=> (defrecord Person [name, age])
user.Person
=> (->Person \"john\" 40)
#user.Person{:name \"john\", :ag         


        
2条回答
  •  醉话见心
    2021-02-02 12:17

    Obviously not in your specific example, but in the general context this operator -> is called the threading operator and is considered one of the thrush operators. Along with its cousin the ->> operator, these operators are quite useful when you need to have code appear more clearly, especially when feeding the output of functions as parameters to another function. Both operators are macros. Here's another SO post concerning both operators.

    I have not yet had cause to use the ->, but did need ->> to make sense of code that needed to compute intermediate values and put them all into one function call.

    Here is another explanation.

提交回复
热议问题