Part of what is so powerful in Clojure is that all the basic data types implement the same sequence abstraction: clojure.lang.ISeq.
This means that functions like "first", "concat", "cons", "map", "rest", etc. work mainly on all of these data types.
My question is this: how can I add my own custom function to the mix and use it for all types that are distributed from ISeq?
The first attempt was to define my own protocol, then "(ext-type clojure.lang.ISeq ...", but this does not work (it compiles, but does not add behavior to the actual types). Another idea was to write a macro that explicitly expresses the βextension typeβ in all types of Clojure (PersistentHashMap, PersistentList, etc.), but this is similar to kludgey.
Is there an elegant / idiomatic way to do this? Perhaps there are many methods?
source share