I'd like to define a record type that implements ISeq and ISeqable, but I want it to work with functions like
map while still outputting the original record type. The record type will "contain" a sequence, but also some other data that I want to stay associated even though I called map.
So, for example:
(defrecord Person [readingList name])
(def p (Person. '("book 1", "book 2") "Jane"))
(map #(capitalize %) p)
; should produce (Person. '("Book 1", "Book 2") "Jane"))
I realize that I could handle mapping the book list outside the record, but for my purposes I want to treat the
Person record as a sequence that happens to have a bit of data that follows it as it is processed.
I'm having a hard time understanding if this is possible. I haven't found a good place that documents Clojure's common individual protocols, and what it requires to implement a specific one.
I thought maybe it'd be possible to do this if I could define
cons, but it doesn't seem like
cons is a protocol function in ISeq or ISeqable since it doesn't take the record itself as its first argument.