Skip to content
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

Vector: assoc exception #27

Closed
djcoin opened this issue Jun 26, 2013 · 4 comments
Closed

Vector: assoc exception #27

djcoin opened this issue Jun 26, 2013 · 4 comments

Comments

@djcoin
Copy link

djcoin commented Jun 26, 2013

Hi,
thanks for this awesome lib :)
I'm not a Clojure programmer and didn't look at the clojurescript implementation yet.

Given a vector, I want to get a new vector expect some of its first elements (for now, just the tail of the vector) then replace (or insert on head ) the first element of this new vector.
Here is a failing sample:

var v1 = _.vector(4, 5); 
var v2 = _.rest(v1); // option1
var v2 = _.drop(1, v1);    // option2
var v3 = _.assoc(v2, 0, 'b');

I get a "No protocol method IAssociative.-assoc defined for type object: (5)"

Is this normal, how can I do what I intended to do ?

Thanks a lot,
Best,
Simon

@swannodette
Copy link
Owner

Yes this isn't a bug, rest and drop and are sequence fns, you'll get back a sequence not a vector. If you want to drop elements and preserve the type look at subvec and pop or use the reducers functionality (sorry not documented yet).

var v1 = _.vector(4, 5); 
var v2 = _.pop(v1);
var v3 = _.assoc(v2, 0, 'b');

@djcoin
Copy link
Author

djcoin commented Jun 26, 2013

Thanks dnolen for your quick answer :)

I was indeed checking http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/subvec.
pop is in the lib but subvec doesn't seem to be.
Also, I think zipper may help me to do this (pretending i'm using the head of a vector then get a new vector with its head changed).

By the way, I saw that dissoc (among other functions) is not documented. I know it may not be your top priority and that it may be sufficient to look up the clojure doc, just wanted to let you know !

Thanks

@swannodette
Copy link
Owner

Oops missing subvec is an oversight. I'll also add docs for dissoc. Thanks for the report!

@swannodette
Copy link
Owner

subvec added and docs for dissoc included as well as a few other missing things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants