Open leek5pin opened 9 years ago
I fixed this, and have decided to open a more general problem relating to a few other functions.
I forgot to make tests.
drop also has the same problem. I will need to go down the list of functions that produce a transducer when an argument is omitted, and update preconditions, and add tests.
map cat mapcat filter remove take take-while take-nth drop drop-while replace partition-by partition-all keep keep-indexed map-indexed distinct interpose dedupe random-sample
Is there a special error when a wrong type of function passed as 'xfrom', or is it just an arity error?
(into [] + [1 2 3 4 5 6]) Error: In function +, the first argument conj! must be a number but is a function.
(println (into [] even? [1 2 3 4 5 6])) Error: In function even?, the first argument conj! must be an integer number but is a function.
I mean the original error, not a processed one.
But conj! is an issue here, obviously.
Oh, then it's just an arity error.
Do we need two cases, based on whether the functions map, into, etc are used as transducers, or not? Because the arguments are different in these two cases.
Yes, this is what I currently have written for into.
(defn into
([argument1 argument2]
{:pre [(check-if-seqable? "into" argument1)
(check-if-seqable? "into" argument2)]}
(clojure.core/into argument1 argument2))
([argument1 argument2 argument3]
{:pre [(check-if-seqable? "into" argument1)
(check-if-function? "into" argument2)
(check-if-seqable? "into" argument3)]}
(clojure.core/into argument1 argument2 argument3)))
Ok, that's fine for now, but we should look more into it later.
I agree.
For now we will be disallowing transducers versions of common functions. Eventually will need a flag to allow them or not.
Error: You cannot pass three arguments to a function into, need two.
(into to from) (into to xform from)
xform is a transducer