Skip to content

Commit 72f112f

Browse files
committed
Merge pull request #422 from mpenet/feature/record-seq
Implement ICounted and ISeqable on records
2 parents 3c8a66a + 373a44d commit 72f112f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

pixie/stdlib.pxi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
(def printf (ffi-fn libc "printf" [CCharP] CInt :variadic? true))
1212
(def getenv (ffi-fn libc "getenv" [CCharP] CCharP))
1313

14-
1514
(def libedit (ffi-library (str "libedit." pixie.platform/so-ext)))
1615
(def readline (ffi-fn libedit "readline" [CCharP] CCharP))
1716
(def rand (ffi-fn libc "rand" [] CInt))
@@ -1286,6 +1285,13 @@ and implements IAssociative, ILookup and IObject."
12861285
@acc#
12871286
(recur (next fields#) acc#)))
12881287
acc#)))
1288+
'ICounted
1289+
`(-count [self] ~(count fields))
1290+
1291+
'ISeqable
1292+
`(-seq [self#]
1293+
(map #(map-entry % (get-field self# %))
1294+
~fields))
12891295

12901296
'IMeta
12911297
`(-with-meta [self# ~meta-gs]

tests/pixie/tests/test-defrecord.pxi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@
6363
(t/assert= [[:one 1] [:two 2] [:three 3]] (reduce conj [] t1))
6464
(t/assert= [1 2 3] (vals t1))
6565
(t/assert= [:one :two :three] (keys t1)))
66+
67+
(t/deftest icounted []
68+
(t/assert= (count t1) 3))
69+
70+
(t/deftest seqable []
71+
(t/assert= (key (first (seq t1))) :one)
72+
(t/assert= (val (first (seq t1))) 1)
73+
(t/assert (instance? LazySeq (seq t1))))

0 commit comments

Comments
 (0)