Hacker News new | past | comments | ask | show | jobs | submit login

and if you then combine s/conform with core.match, you can build really elegant code to traverse these structures.



Why not just pattern match immediately if you are going to bother with using core.match?


How would you pattern match with Clojure without using core.match? Do you mean using another library?

Edit: oh I understand what you mean, you were thinking of skipping the s/conform part, and use core.match directly. Personally, I consider spec an excellent library to describe the shape of data, and core.match allows for better describing the actions you want to take based upon that.

For example, with spec you can define a bunch of alternatives using s/or, and then use core.match to then easily traverse the results.

It’s more a matter of separation of concerns to me. I don’t use core.match for validation or describing shapes of data.


Do you have to adapt spec definition to core.match somehow? Is there a resource to read more how to use them together?


No you don't have to do anything.

Let's say I have something like

  (s/def :thespec (s/or :foo ::foo 
                        :bar ::bar))
I can then use it in conjunction with core.match like

  (match [(s/conform :thespec val)]
    [:foo x] (do-something-with x)
    [:bar y] (do-something-else-with y))
Which imho is an easier way to navigate these things.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: