-
Notifications
You must be signed in to change notification settings - Fork 257
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
No generic collection type? #384
Comments
You are the second person to ever ask about this -- here is the first: I would still say the same thing: I can see the utility, but myself have never needed it (since usually I care whether the collection is sequential or not). We'd be open to a PR that adds this, but I would like to hear a bit about your use case first if you don't mind sharing. |
I believe you when you say you never needed it and only one person ever asked. Still, I'm surprised. The "collection" concept is all over clojure, tons of core functions accept collections as arguments. So any function that calls This particular use case is a clojurescript reagent component that is making a pretty HTML table. It doesn't really care about the collection type, if the caller wants no duplicates he can coerce to a set himself. If the caller has already sorted the contents, he can pass in a sequence. So neither a set nor a sequence seems to be the correct schema here. I don't think it's correct to force the argument to a sequence, that puts a burden on the caller for no other purpose than satisfying schema. |
OK, that makes sense -- thanks for the info. I guess there's also some concern about making coercion work properly -- I'm not sure if |
FWIW, my team would find it useful to have a schema type that allows either [Foo] or #{Foo}. We have a bunch of functions that need to take a collection of items of a given type, where order doesn't matter. Some callers have those items in a set and some have them in vectors. |
You can do this with
(s/cond-pre [Foo] #{Foo} )
https://github.com/plumatic/schema#other-schema-types
…On Thu, Jun 13, 2019 at 5:28 PM Aaron Iba ***@***.***> wrote:
FWIW, my team would find it useful to have a schema type that allows
either [Foo] or #{Foo}.
We have a bunch of functions that need to take a collection of items of a
given type, where order doesn't matter. Some callers have those items in a
set and some have them in vectors.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#384?email_source=notifications&email_token=ABWBOB4URWK5TPFENPONQLTP2LQ4FA5CNFSM4DEM4ON2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXVMLEY#issuecomment-501925267>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWBOBYAL73LZKJILSUTNL3P2LQ4FANCNFSM4DEM4ONQ>
.
|
Another use-case: the result of |
How can I define a collection spec that works on all collections (not just vectors or sets)?
To illustrate the issue I'm having:
It seems like one of these should work, or if they don't, there should be a third option where the schema is "I don't care what type of collection it is, as long as each item in it is an Int".
I can get what I want, sort of, with a little function I define myself, but seems like there ought to be a better way:
The text was updated successfully, but these errors were encountered: