-
-
Save cgrand/425222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
;;------------------------------------------------------------------------------
(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