Add instance check functions to defrecord/deftype

Description

It is often necessarty to test for instance? on deftypes/defrecords, this patch makes the two macros automatically generate a type? function implemented as (fn [x] (instance? type x)), to complement ->type and map->type
Example:

Environment

None

Activity

Show:
Jozef Wagner
October 9, 2014, 3:11 PM

What about camel cased types? predicate SomeType? does not look like an idiomatic type predicate. I suggest to have this type predicate function and its name optional, through e.g. redicate metadata on a type name. Moreover, it is far more useful to have such predicate on protocols, rather than types.

Nicola Mometto
October 9, 2014, 3:17 PM

I don't think camel cased types should pose any issue. we use ->SomeType just as fine, I don't see why SomeType? should be problematic.

I disagree that it's more useful to have a predicate for protocols since protocols are already regular Vars and it's just a matter of (satisfies? theprotocol x), the value of the predicate on types/record is to minimize the necessity of having to import the actual class

Pierre-Yves Ritschard
January 6, 2017, 3:47 PM

This would be super useful, thanks.

Declined

Assignee

Unassigned

Reporter

Nicola Mometto

Labels

Approval

None

Patch

Code

Priority

Minor