I have a data structure in Clojure, which is a collection of experimental results:
(defprotocol ResultSet (columns [rs] "return a collection of the columns in the resultset, represented by keywords") (rows [rs] [rs column-keys] "returns a seq of the rows in the resultset, order and column specified as keywords by column-keys. with a single argument returns rows with all columns present"))
And I have deftype that implements this protocol. I am interested in writing functions that perform functions such as displaying a function for all results in a result set, or that add up for a set of results, basically doing the same thing as the built-in seq functions.
In Haskell, I would do this by executing the appropriate classes (like Functor) and then using functions like fmap or mfilter. So I reviewed this in Clojure and got some ideas about implementing the ISeq interface.
So is this a good idea? I canโt find many resources for implementing ISeq, and Iโm wondering what an idiomatic approach to this is.
source share