Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by
edited by

I'm trying to create a collection that plays well with clojure. This is what I came up with:

https://gist.github.com/fctorial/201dc99080528b4e626245a29f342361

I've tried to make it behave like 'PersistentList'. But there's an issue with it. Sometimes an empty collection of this type resolves to '(nil)' when working with it in clojure:

(seq (ROVec. (byte-array 0)))
=> (nil)
(vec (ROVec. (byte-array 0)))
=> []
(vec (seq (ROVec. (byte-array 0))))
=> []
(lazy-seq (ROVec. (byte-array 0)))
=> (nil)
(vec (lazy-seq (ROVec. (byte-array 0))))
=> [nil]

I think the issue is '.first' for an empty ROVec returns nil, just like it does for 'PersistentList'. How do I fix this?

1 Answer

0 votes
by

I changed the class so that now it extends ISeq instead of ASeq and implemented method seq() to return null when the collection is empty.

by
Also, have you tried https://github.com/ztellman/collection-check ? "This is both a validation that the data structure is correct and that it implements all necessary interfaces."
...