Skip to content

Methods .mapv(), .mapv_into(), .apply(), .applyv(), .visit()#159

Merged
bluss merged 7 commits intomasterfrom
experiments
Mar 16, 2016
Merged

Methods .mapv(), .mapv_into(), .apply(), .applyv(), .visit()#159
bluss merged 7 commits intomasterfrom
experiments

Conversation

@bluss
Copy link
Member

@bluss bluss commented Mar 16, 2016

Fixes #58
Fixes #153

I did experiment with a trait to unify the map and mapv case into a single method, and while it worked, it also introduced type inference ambiguities everywhere, so it was so much less useful.

@bluss
Copy link
Member Author

bluss commented Mar 16, 2016

I am taking suggestions for a good naming scheme for the methods .map(), .mapv(), .apply(), .applyv(), .visit().

We do want them all as this kind of "internal iteration" or closure visiting; it's the only way we can optimize the traversal across nested loops if needed.

We do want both .map and .mapv and the same with .apply, .applyv, because the by value methods are so convenient for numerical code.

@daniel-vainsencher
Copy link
Contributor

Map should definitely stay map. Apply doesn't explain that mutation is going to happen. Maybe transform? I doubt I'd ever find out about the v versions, I would be using & because I've gotten used to this inconvenience :( I don't have a better name, though. Visit is fine, IMO.

@bluss
Copy link
Member Author

bluss commented Mar 16, 2016

Thanks for the input! They will be next to each other in the docs, so I hope you'd see them there.

This is tricky because mathematically, all four methods do the same thing. So we're trying to find words for that..

@bluss
Copy link
Member Author

bluss commented Mar 16, 2016

Oh no, there's yet another one that comes up, mapv_into. (Map by value, return the input).

Again, all of these are the same mathematically, just with different rust type system effects.

 .map(&self, |&A| -> B) -> OwnedArray<B, D>
 .mapv(&self, |A| -> B) -> OwnedArray<B, D>
 .mapv_into(self, |A| -> A) -> Self
 .apply(&mut self, |&mut A|)
 .applyv(&mut self, |A| -> A)
 .visit(&self, |&A|)

@bluss bluss force-pushed the experiments branch 2 times, most recently from 4d09f58 to d52e432 Compare March 16, 2016 15:30
@bluss bluss changed the title Experiments with .mapv(), .apply(), .applyv(), .visit() Experiments with .mapv(), .mapv_into(), .apply(), .applyv(), .visit() Mar 16, 2016
@bluss bluss changed the title Experiments with .mapv(), .mapv_into(), .apply(), .applyv(), .visit() MEthods .mapv(), .mapv_into(), .apply(), .applyv(), .visit() Mar 16, 2016
@bluss bluss changed the title MEthods .mapv(), .mapv_into(), .apply(), .applyv(), .visit() Methods .mapv(), .mapv_into(), .apply(), .applyv(), .visit() Mar 16, 2016
bluss added a commit that referenced this pull request Mar 16, 2016
Methods .mapv(), .mapv_into(), .apply(), .applyv(), .visit()
@bluss bluss merged commit c5e307a into master Mar 16, 2016
@bluss bluss deleted the experiments branch March 16, 2016 23:31
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

Successfully merging this pull request may close these issues.

2 participants