Skip to content

Instantly share code, notes, and snippets.

@cgrand cgrand/cs2.clj forked from ejackson/cs2.clj
Created Jun 4, 2010

Embed
What would you like to do?
(deftype Timeseries
[series] ; maybe dataset or backing-set or something like that
Object
(equals [this other]) ; should a TS be equal to any kind of coll holding same value or to other TS only? (the easiest answer is "any kind of coll")
(hashCode [this]) ; depends on ^^
(toString [this])
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/IPersistentCollection.java
clojure.lang.IPersistentCollection
(cons [this a] series) ; for the basic TS all these methods will simply delegate to series
(empty [this] series)
(equiv [this o] series)
(count [this o] series)
(seq [this o] seris)
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/IPersistentStack.java
clojure.lang.IPersistentStack
(peek [this] series) ; here you'll have to use rseq on the backing set
(pop [this] series) ; implemented using peek
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Sorted.java
clojure.lang.Sorted
(comparator [this] series) ; delegated
(entryKey [this entry] series) ; delegated
(seq [this ascending] series) ; delegated
(seqFrom [this key ascending] series)) ; delegated
@ejackson

This comment has been minimized.

Copy link

commented Jun 7, 2010

;;------------------------------------------------------------------------------
(deftype timeseries

[dataset]

;;----------------------------------------------------------------------------
Object

;; Defined in terms of hashCode. Is this cheating / stupid ?
(equals [this other](= %28.hashCode this%29
%28.hashCode other%29))

;; Delegated
(hashCode [this](hash dataset))

;; Straight delegation
(toString [this](str dataset))

;;----------------------------------------------------------------------------
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/IPersistentCollection.java
clojure.lang.IPersistentCollection

;; I want to go (timeseries (conj dataset a)) but this flakes ?
(cons [this a](conj dataset a))

(empty [this](-> dataset empty))

;; How does this differ from equals
(equiv [this o]
dataset)

;; Not in the interface
;;(count [this o] dataset)

;; This duplicates the method in Sorted ?
(seq [this](seq dataset))

;;----------------------------------------------------------------------------
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/IPersistentStack.java
clojure.lang.IPersistentStack
(peek [this](-> dataset rseq first))

;; Use the fact that dataset is a set, what do you think ?
(pop [this](disj dataset %28peek dataset%29))

;;----------------------------------------------------------------------------
;; http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Sorted.java
clojure.lang.Sorted

;; Delegated
(comparator [this](comparator dataset))

;; Delegated. Go to Java
(entryKey [this entry](.entryKey dataset entry))

;; Delegated
(seq [this ascending](.seq dataset ascending))

;; Delegated. Go to Java
(seqFrom [this key ascending](.seqFrom dataset key ascending))) ; delegated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.