ztellman/clj-tuple

Implement IFn

reiddraper opened this issue · 3 comments

Thoughts on whether tuple should implement IFn? Currently:

user=> ([0 1] 0)
0
user=> ((clj-tuple/tuple 0 1) 0)
ClassCastException clj_tuple.Tuple2 cannot be cast to clojure.lang.IFn  user/eval1843 (NO_SOURCE_FILE:1)

Or is this a it's not constant-time thing, so don't want to encourage random access? Looks like list doesn't support IFn or associative either.

No, it's constant-time. I made the tuples resemble lists because it was less work for me, not because it was more appropriate. I should have them act like vectors, which means that I need to implement the following:

IFn
Associative
IPersistentVector
Reversible
Entry (for the 2-tuple case)

and maybe some others. I'll get to it soon.

Awesome. I just started using it in simple-check, in the tuples branch. Very useful for me because now that tuples have a distinct type from vectors, shrinking can preserve the size.