Partial
Partial is a great function. The doc (doc partial) describes it as taking function f and fewer than the normal arguments to f. What is returned is a function that a variable number of remainder args. There are many potential applications and allow you to essentially create duplicate but similar functions without code duplication.
(def only-strings (partial filter string?))
(only-strings ["first test" :anothertest 3 4 "last test"])
("first test" "last test")
Tagged Literals
I mentioned a tagged literal in my last post. Namely the #inst "2012" part. That convenience is a tagged literal for creating a date. I accidently noticed there's a new one in the build i've done from github. That's the #uuid which seems to have appeared from 1.4-alpha4. It appears there aren't many available beyond that yet but they're definitely worth keeping an eye on as they're very handy. Hopefully at some point i'll do a post on creating your own.
No comments:
Post a Comment