You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a ReQL command to interate over an array. #2574
I agree. However, I think the name map should not be overloaded for either of these things. Also, I think the parallel-mapping version shouldn't be variadic -- it should only take two sequences. This is to keep things simple. It could be painlessly extended later to support variadic arguments.
I think, also, an r.range(begin, end) command would be nice to have (especially as a developer inserting dummy test data into tables). It might be gross if it supported infinite ranges, though, and a finite-range-emitting version of the command would not, in combination of a parallel-mapping map command, be enough to implement the map-with-index command you've asked for.
However, if we wanted an infinitely-generating r.range command (that produces the ordered sequence 0, 1, 2, 3, ...), and if we had parallel-map, that would be one reason not to add map-with-index functionality (because it's redundant). (I think infinite sequences would be okay as long as we disallow a query from returning an infinite sequence. Perhaps unless the user says they're explicitly allowed.)
Also, sequence.mapWithNumericPosition(function(idx, elem){...}) is a bit more convenient than sequence.doAParallelMapPlease(r.range(0), function(elem, idx){...}). (We need some non-bogus ideas for what these commands would be named, too.)
Also, note that parallel-map only makes sense on arrays and other ordered sequences, but not on unordered result sets like an r.table('foo') that doesn't have an orderBy attached.
Ruby has an each_with_index function; we could have map_with_index by analogy. (Also, just to be clear, why do you think making map variadic would be bad? I'm not sure I disagree, but it isn't obvious to me.)
Also, just to be clear, why do you think making map variadic would be bad?
I think it might be bad. Unknown unknowns. r.args. The fact that many drivers aren't good at that sort of thing. The code would be more complicated. The fact that in all the Haskell use I've had, almost never have I needed wanted zip3. (Edit: wanted. You never need zip3.)
Instead of a two-argument map, we might just want a plain parallel-merge function that takes two sequences and merges them into a sequence of objects {left: ..., right: ...}. One sequence can be shorter than another, and this provides a non-ambiguous way to communicate that information, in the case where the sequences have unequal length, by making the last documents have only a {left: } or {right: } field.
Actually, moving this into 1.14. We might not get to it, but I'd like to talk about it this proposal-cycle because it's a major thing people can't do right now (I just saw another example of this today).
Alright, an update: since r.range is already in and it's not totally trivial to check the arity of a JS function, we're leaving out the version where people pass a function of arity one higher than the number of streams. If people complain a lot about adding r.range, we can put that version back in but since we were on the fence to begin with I would guess we won't.
We're currently implementing r.map in such a way that when it is passed a single stream it's evaluated lazily as before. However, when it's passed multiple streams we have to evaluate them in an eager fashion, which is slightly less efficient.
Since we can't trivially check the arity of a JS function the only option was to always pass the extra index stream, and JS will happily ignore it when it's superfluous. This would mean that every r.map which is passed a JS function would be evaluated eagerly though, and we're not willing to accept this performance hit at the moment.
Additionally, adding this functionality at a later date won't break backwards compatibility thus we're holding off on it for the moment.
The arity problem shows up in Lua as well. I am using the number of arguments to do to guess at arity. I expect the same hack can be applied to map after this is implemented.
@neumino The problem here is actually determining the number of arguments from a string passed into r.js. As in table.map(r.js("function (x, c) { return "How many arguments does this function have?"; } "))
@danielmewes -- Angular calls (used to?) toString() on a function and then parse the number of arguments with a regex (that's how they are doing injection).
The data explorer does the same to keep track of the VAR terms.
@neumino That's interesting. I'm not sure if we should do that though. It sounds like it would be a rather complex (and accordingly error-prone) regex.
Generally, as @VeXocide mentioned, we have the option of adding the implicit count-argument late without breaking compatiblity.
Activity
srh commentedon Jun 19, 2014
I agree. However, I think the name
mapshould not be overloaded for either of these things. Also, I think the parallel-mapping version shouldn't be variadic -- it should only take two sequences. This is to keep things simple. It could be painlessly extended later to support variadic arguments.I think, also, an
r.range(begin, end)command would be nice to have (especially as a developer inserting dummy test data into tables). It might be gross if it supported infinite ranges, though, and a finite-range-emitting version of the command would not, in combination of a parallel-mapping map command, be enough to implement the map-with-index command you've asked for.However, if we wanted an infinitely-generating
r.rangecommand (that produces the ordered sequence0, 1, 2, 3, ...), and if we had parallel-map, that would be one reason not to add map-with-index functionality (because it's redundant). (I think infinite sequences would be okay as long as we disallow a query from returning an infinite sequence. Perhaps unless the user says they're explicitly allowed.)Also,
sequence.mapWithNumericPosition(function(idx, elem){...})is a bit more convenient thansequence.doAParallelMapPlease(r.range(0), function(elem, idx){...}). (We need some non-bogus ideas for what these commands would be named, too.)Also, note that parallel-map only makes sense on arrays and other ordered sequences, but not on unordered result sets like an
r.table('foo')that doesn't have an orderBy attached.mlucy commentedon Jun 19, 2014
Ruby has an
each_with_indexfunction; we could havemap_with_indexby analogy. (Also, just to be clear, why do you think makingmapvariadic would be bad? I'm not sure I disagree, but it isn't obvious to me.)srh commentedon Jun 19, 2014
I think it might be bad. Unknown unknowns.
r.args. The fact that many drivers aren't good at that sort of thing. The code would be more complicated. The fact that in all the Haskell use I've had, almost never have Ineededwanted zip3. (Edit: wanted. You never need zip3.)Instead of a two-argument map, we might just want a plain parallel-merge function that takes two sequences and merges them into a sequence of objects
{left: ..., right: ...}. One sequence can be shorter than another, and this provides a non-ambiguous way to communicate that information, in the case where the sequences have unequal length, by making the last documents have only a{left: }or{right: }field.mlucy commentedon Jun 19, 2014
Too bad we already use
zipfor the opposite ofzip.mlucy commentedon Jun 19, 2014
I'm putting this in subsequent since @coffeemug is out of town and I don't want to forget about it.
mlucy commentedon Jun 20, 2014
Actually, moving this into 1.14. We might not get to it, but I'd like to talk about it this proposal-cycle because it's a major thing people can't do right now (I just saw another example of this today).
coffeemug commentedon Jun 24, 2014
Moving to 1.14-polish. This isn't as important as major features, and I'd like to agree on those first. We can tackle this later.
59 remaining items
mlucy commentedon Oct 14, 2014
Alright, an update: since
r.rangeis already in and it's not totally trivial to check the arity of a JS function, we're leaving out the version where people pass a function of arity one higher than the number of streams. If people complain a lot about addingr.range, we can put that version back in but since we were on the fence to begin with I would guess we won't.VeXocide commentedon Oct 14, 2014
We're currently implementing
r.mapin such a way that when it is passed a single stream it's evaluated lazily as before. However, when it's passed multiple streams we have to evaluate them in an eager fashion, which is slightly less efficient.Since we can't trivially check the arity of a JS function the only option was to always pass the extra index stream, and JS will happily ignore it when it's superfluous. This would mean that every
r.mapwhich is passed a JS function would be evaluated eagerly though, and we're not willing to accept this performance hit at the moment.Additionally, adding this functionality at a later date won't break backwards compatibility thus we're holding off on it for the moment.
neumino commentedon Oct 14, 2014
In JavaSript, you can check the number of arguments with
In CoffeeScript, you can use
lenArgs = (args...) -> args.length.asakatida commentedon Oct 14, 2014
The arity problem shows up in Lua as well. I am using the number of arguments to
doto guess at arity. I expect the same hack can be applied tomapafter this is implemented.danielmewes commentedon Oct 14, 2014
@neumino The problem here is actually determining the number of arguments from a string passed into
r.js. As intable.map(r.js("function (x, c) { return "How many arguments does this function have?"; } "))neumino commentedon Oct 14, 2014
@danielmewes -- Angular calls (used to?)
toString()on a function and then parse the number of arguments with a regex (that's how they are doing injection).The data explorer does the same to keep track of the
VARterms.danielmewes commentedon Oct 14, 2014
@neumino That's interesting. I'm not sure if we should do that though. It sounds like it would be a rather complex (and accordingly error-prone) regex.
Generally, as @VeXocide mentioned, we have the option of adding the implicit count-argument late without breaking compatiblity.
VeXocide commentedon Oct 14, 2014
In CR 2200 by @gchpaco.
VeXocide commentedon Oct 14, 2014
I'll create a new issue for the implicit index, this clearly needs to be given some more thought.
marshall007 commentedon Oct 15, 2014
@neumino @danielmewes in JavaScript, a function's
lengthproperty indicates how many arguments it takes. Example:robert-zaremba commentedon Oct 16, 2014
Maybe the option will be, as discussed above, to add other function with explicit argument (
mapWithIndex,zipWith...)?VeXocide commentedon Oct 22, 2014
Merged into
nextvia commit 54fa558.