Live data from Hacker News

Structural Typing for Clojure

github.com

11–14 of 14 posts

Re: Structural Typing for Clojure

#11

I've had good luck with prismatic schema https://github.com/Prismatic/schema , which seems to be along a similar direction. It's fairly low commitment and can lead to big gains fairly quickly. I assume this would be similar.

Ditto. Augmenting my code with schema has also been a life saver in terms of documenting the input and output types of functions (e.g. complex, deeply-nested maps) so I can return to code months later and understand what's going on.

Re: Structural Typing for Clojure

#12

I've had good luck with prismatic schema https://github.com/Prismatic/schema , which seems to be along a similar direction. It's fairly low commitment and can lead to big gains fairly quickly. I assume this would be similar.

Everything that's been said is about prismatic schema is great. We've found the most benefit from using schema as a documentation tool. i.e. This is what an order-request, customer, order, etc. looks like.

Re: Structural Typing for Clojure

#13
It would be interesting to see a "When structural-typing is better than prismatic/schema" section in the readme. I read the readme, and I don't see why you can't use something like s/validate instead of built-like. So instead of:

    (type! :Point (requires :x :y))
    (some->> points
         (all-built-like :Point)
         (map color)
         (map embellish))
To keep it simple, as in the first example of the whirlwind tour, we could use:

    (def Point {:x s/Any :y s/Any})
    (some->> points
         (s/validate [Point])
         (map color)
         (map embellish))

It's good that structural-typing does not use macros, instead building ontop of specter which is pretty cool. So is there a performance enhancement?

It's clear that one should use structural-typing where an expertise with specter has been attained, Not sure when else it's the best choice.

Re: Structural Typing for Clojure

#14

I've had good luck with prismatic schema https://github.com/Prismatic/schema , which seems to be along a similar direction. It's fairly low commitment and can lead to big gains fairly quickly. I assume this would be similar.

Prismatic Schema is wonderful. One useful property is that a schema is just a regular data structure (often a map). So you're free to use regular data structure processing functions:

    (def Customer {:customer-id s/Int, :address-id s/Int}

    (def ProcessedCustomer (merge Customer {:external-id s/Int}))
Post reply on HN