-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure into
spec to better fit possible usages
#64
Comments
I will leave the internal definition of (defn into
"Returns a new coll consisting of to with all of the items of
from conjoined. A transducer may be supplied.
(into x) returns x. (into) returns []."
{:added "1.0"
:static true}
([] [])
([to] to)
([to from]
(if (instance? clojure.lang.IEditableCollection to)
(with-meta (persistent! (reduce conj! (transient to) from)) (meta to))
(reduce conj to from)))
([to xform from]
(if (instance? clojure.lang.IEditableCollection to)
(let [tm (meta to)
rf (fn
([coll] (-> (persistent! coll) (with-meta tm)))
([coll v] (conj! coll v)))]
(transduce xform rf (transient to) from))
(transduce xform conj to from)))) |
This is our spec on (s/fdef clojure.core/into
:args (s/and :babel.arity/zero-to-three
(s/or :arg-one (s/cat :any (s/? any?))
:arg-two (s/cat :coll (s/nilable :babel.type/coll) :any any?)
:arg-three (s/cat :coll (s/nilable :babel.type/coll) :function :babel.type/function-or-lazy :coll any?)))) |
@elenam Here are some discoveries I made today while diving down this rabbit hole, which may influence how we rewrite these specs going forward. There are two key invariants on
What does Case I: From documentation:
Therefore, we can expect that:
i.e.,
Case II: From documentation:
It's not stated here, but I suspect that, by "contains no items," they actually mean that Also, this invariant applies to cases with two arguments, in which i.e., define With one argument: With two arguments: |
One proposed idea for spec on one-argument: any? two-arguments: ((first: coll?) and (second: (seqable? and non-empty?))) |
into
is simultaneously under-spec'd and over-spec'd right now due to some weird edge cases that come with the function. Officially, the documentation notes that, with two arguments,into
should take two collections, but there are several cases where this is not true.to
is any value or expression, andfrom
is an empty collection,(into to from)
returns evaluation ofto
.from
is a non-empty collection,(into nil from)
performs conj on(list (first from))
and the rest of the list, regardless of what the type of collectionfrom
is.Same result in Babel.
to
is a string, andfrom
is a non-empty string,(into to from)
throws an exception.Correctly fails Babel spec, though might need to be improved, since the message is wrong (see below):
from
is an empty string:to
is a collection andfrom
is not. In these cases, we get an error onseq
instead (which is also a problem. See: Need spec onseq
#63).The text was updated successfully, but these errors were encountered: