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
I think that in addition to attribute names, we should let people pass patterns to pluck specified as objects, with the following semantics:
If an attribute maps to true, include that attribute.
If an attribute maps to an object, recurse into that object.
If an attribute maps to an array, recurse into that array.
If an attribute maps to NULL or false, exclude it. (This is useful because it allows people to construct plucks that behave differently based on a piece of code they execute.)
So it actually seems like there's now a huge number of ways to perform a pluck and I fear it may wind up a bit confusing. I'm having a lot of trouble wrapping my head around all the different behaviors. A few things that seem weird to me:
mapping to true to mean "include this" seems really weird. In particular it's weird that at the top level I say:
obj.pluck("foo", "bar")
but if it's a level down I say:
obj.pluck({"foo" : {"foo" : True, "bar" : True}})
I'd much prefer if the syntax looked like this:
obj.pluck({"foo" : ["foo", "bar"]})
it's more concise and it means nested pluck looks very similar to unnested pluck. In fact this might be an argument for replacing variadic pluck with pluck on an array (i.e pluck(["foo", "bar"]) instead of pluck("foo", "bar")) which would make them look identical.
Your use of arrays here doesn't make any sense to me there aren't any examples of a multi element array does that have any meaning in this scheme? When you call pluck on an array at the top level it automatically maps the pluck over the array. Why can't we do the same thing for sub arrays? Rewriting a relevant example:
The whole functional syntax seems like it might be a bit too complicated. It's also unclear to me how this works if you're running pluck on a sequence. It seems like all of your examples hinge on having the object in scope to execute the function. What would it look like executed on a sequence?
How would you represent obj.pluck({:a => {:b => {:c => true}, :d => true}}) in your scheme? As obj.pluck({:a => [{:b => [:c]}, :d]})? It's much less obvious what that does at first sight, at least to me. I think we should at least provide people the option to use the boolean notation.
I'd be fine with having pluck automatically map over arrays when it recurses down. I think that's probably what people will want. If we do this, then we could re-purpose arrays to match your proposed syntax and just accept both (i.e. {:a => {:b => true}} is identical to {:a => [:b]} or {:a => :b}).
The examples with obj inside of pluck were just meant to demonstrate that you could provide an arbitrary predicate in addition to a literal true or false. I re-used obj because I didn't want to introduce a new variable, but in retrospect it just made the examples confusing. I wasn't really trying to say anything special there.
I'm still not seeing a place where we really need the mapping to true syntax.
- Automatically recursing seems great to me.
- Ah I see. So you can't for example provide a function that references the rows of a sequence? I think that would be too complicated for `pluck`.
The first seems to read better, at least to me, because the structure of what you type exactly matches the structure of your output. When I read the second one I have to think for a second about what the resulting object will look like.
That might just be me, though, and the second one is definitely shorter.
We'll also have to extend this syntax (whatever it will end up) to without and possible many other functions we missed. We should consider the list of functions this applies to carefully.
I think I like the original proposal much more than JD's proposal. { :a => { :b => true }} seems much more clear to me than { :a => b }. The former is a bit longer, but it reads very intuitively (possibly because it maps directly to the object's structure?), where's the latter seems odd. @neumino, @mglukhovsky, what do you think?
(Also, the original proposal seemed odd to me initially, but I really grew to like it after sleeping on it for a bit. It does what we need and is pretty intuitive, IMO. We'd be hard-pressed to do much better (not that we shouldn't try))
I think the main thing that bugs me about the map solution is that it's actually going to lead to a lot of typing as soon as you're plucking any reasonably large number of fields. I just worry that after a bit of serious use it would start to feel like you were having to type the word True an awful lot to accomplish what you wanted. This is exacerbated by the fact that if you want to pluck nested attributes at all you need to convert everything to a map for example:
# suppose you have the codeobj.pluck("id", "user", "location", "text", "date", "created_at")
# and you decide you just want the "name" attribute # from the "user" field not the whole structure# you have to change your code to:obj.pluck({"id" : True, "user" : {"name" : True}, "location" : True, "text" : True, "date" : True, "created_at" : True})
# instead ofobj.pluck("id", {"user" : True}, "location", "text", "date", "created_at")
It just seems like hitting that linear increase in typing is going to be really annoying. @neumino, @mglukhovsky and @al3xandru what do you guys think about it?
Also it's worth considering that this syntax is going to apply in a number of other places. Such as has_fields, without, group_bycontains which aren't going to benefit from having the structure of the pluck specifier (or whatever we want to call it) looking like the structure of their output (although I suppose they still look like the input). But we should consider how usable the extra verbosity would be with those
Ok, just talked to @jdoliner and he felt the same way as @mlucy (in that we've discussed this ad-nauseum, if we let this sit we'll come back to it and have to waste a bunch of time getting to where we are now, etc.)
So I retract my previous comment. Let's just do it as discussed and see what happens.
@jdoliner -- it would be really nice if we ended up with some sort of pathspec_t at the end of this so that we could easily use the same paths in other commands.
This is almost done I just need to confer with @mlucy about how to make it not recurse into nested arrays. It also needs tests and docs but it should be done by tomorrow.
I didn't want to do it on other commands without some formal discussion. I
think we should just have an issue for next sprint where we discuss which
functions should take pathspecs and what the semantics should be. Hopefully
this will be pretty straight forward.
Does the new syntax apply only to pluck or other ops too (without, etc.?)
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/889#issuecomment-20220992
.
Cool, I think we'll market this as experimental syntax for 1.7, get feedback on it, roll it into all relevant commands in 1.8 with any enhancements we might do based on the feedback, and market it as a full-blown feature then. This works out really well, actually.
Activity
coffeemug commentedon Jun 11, 2013
Moving to 1.7. A couple of comments on this proposal:
with_fieldsandhas_fieldsobj.pluck({:a => {:b => true}}, :c)mlucy commentedon Jun 11, 2013
I agree on both.
neumino commentedon Jun 11, 2013
Are we keeping the current behavior?
Can I still pass a string or multiple strings to pluck (first level fields)?
If yes, I would be cool with the proposal.
coffeemug commentedon Jun 11, 2013
Yes, we're also keeping the current behavior (at least I always assumed that's part of this proposal).
neumino commentedon Jun 11, 2013
Sounds good to me then.
jdoliner commentedon Jun 11, 2013
So it actually seems like there's now a huge number of ways to perform a
pluckand I fear it may wind up a bit confusing. I'm having a lot of trouble wrapping my head around all the different behaviors. A few things that seem weird to me:trueto mean "include this" seems really weird. In particular it's weird that at the top level I say:but if it's a level down I say:
I'd much prefer if the syntax looked like this:
it's more concise and it means nested pluck looks very similar to unnested pluck. In fact this might be an argument for replacing variadic pluck with pluck on an array (i.e
pluck(["foo", "bar"])instead ofpluck("foo", "bar")) which would make them look identical.pluckon an array at the top level it automatically maps thepluckover the array. Why can't we do the same thing for sub arrays? Rewriting a relevant example:Would become
mlucy commentedon Jun 11, 2013
@jdoliner --
obj.pluck({:a => {:b => {:c => true}, :d => true}})in your scheme? Asobj.pluck({:a => [{:b => [:c]}, :d]})? It's much less obvious what that does at first sight, at least to me. I think we should at least provide people the option to use the boolean notation.{:a => {:b => true}}is identical to{:a => [:b]}or{:a => :b}).objinside ofpluckwere just meant to demonstrate that you could provide an arbitrary predicate in addition to a literaltrueorfalse. I re-usedobjbecause I didn't want to introduce a new variable, but in retrospect it just made the examples confusing. I wasn't really trying to say anything special there.jdoliner commentedon Jun 11, 2013
obj.pluck({:a => {:b => :c}}, :d)
mlucy commentedon Jun 11, 2013
I think
obj.pluck({:a => {:b => :c}}, :d)isobj.pluck({:a => {:b => {:c => true}}, :d => true}}), notobj.pluck({:a => {:b => {:c => true}, :d => true}}), unless I misunderstood your syntax.jdoliner commentedon Jun 11, 2013
Oh sorry, these are getting hard to read. I think the actually way to do it then would be:
mlucy commentedon Jun 11, 2013
The first seems to read better, at least to me, because the structure of what you type exactly matches the structure of your output. When I read the second one I have to think for a second about what the resulting object will look like.
That might just be me, though, and the second one is definitely shorter.
What do other people think?
coffeemug commentedon Jun 11, 2013
We'll also have to extend this syntax (whatever it will end up) to
withoutand possible many other functions we missed. We should consider the list of functions this applies to carefully.coffeemug commentedon Jun 11, 2013
I think I like the original proposal much more than JD's proposal.
{ :a => { :b => true }}seems much more clear to me than{ :a => b }. The former is a bit longer, but it reads very intuitively (possibly because it maps directly to the object's structure?), where's the latter seems odd. @neumino, @mglukhovsky, what do you think?(Also, the original proposal seemed odd to me initially, but I really grew to like it after sleeping on it for a bit. It does what we need and is pretty intuitive, IMO. We'd be hard-pressed to do much better (not that we shouldn't try))
jdoliner commentedon Jun 11, 2013
I think the main thing that bugs me about the map solution is that it's actually going to lead to a lot of typing as soon as you're plucking any reasonably large number of fields. I just worry that after a bit of serious use it would start to feel like you were having to type the word
Truean awful lot to accomplish what you wanted. This is exacerbated by the fact that if you want to pluck nested attributes at all you need to convert everything to a map for example:It just seems like hitting that linear increase in typing is going to be really annoying. @neumino, @mglukhovsky and @al3xandru what do you guys think about it?
Also it's worth considering that this syntax is going to apply in a number of other places. Such as
has_fields,without,group_bycontainswhich aren't going to benefit from having the structure of the pluck specifier (or whatever we want to call it) looking like the structure of their output (although I suppose they still look like the input). But we should consider how usable the extra verbosity would be with those47 remaining items
coffeemug commentedon Jun 24, 2013
Ok, just talked to @jdoliner and he felt the same way as @mlucy (in that we've discussed this ad-nauseum, if we let this sit we'll come back to it and have to waste a bunch of time getting to where we are now, etc.)
So I retract my previous comment. Let's just do it as discussed and see what happens.
jdoliner commentedon Jun 24, 2013
Working on this now since it seems like the most important optional issue.
mlucy commentedon Jun 24, 2013
@jdoliner -- it would be really nice if we ended up with some sort of
pathspec_tat the end of this so that we could easily use the same paths in other commands.mlucy commentedon Jun 24, 2013
(also,
as_pathspeconval_tanddatum_twould make this really nice to implement in the other commands that we want to support paths)jdoliner commentedon Jun 27, 2013
This is almost done I just need to confer with @mlucy about how to make it not recurse into nested arrays. It also needs tests and docs but it should be done by tomorrow.
coffeemug commentedon Jun 27, 2013
🙇
jdoliner commentedon Jun 28, 2013
This is in next as of 8c6b353. Ships in 1.7 CR 677 by @mlucy.
coffeemug commentedon Jun 29, 2013
Does the new syntax apply only to
pluckor other ops too (without, etc.?)mlucy commentedon Jun 29, 2013
Just
pluckfor 1.7.jdoliner commentedon Jun 29, 2013
I didn't want to do it on other commands without some formal discussion. I
think we should just have an issue for next sprint where we discuss which
functions should take pathspecs and what the semantics should be. Hopefully
this will be pretty straight forward.
On Fri, Jun 28, 2013 at 5:15 PM, coffeemug [email protected] wrote:
coffeemug commentedon Jun 29, 2013
Cool, I think we'll market this as experimental syntax for 1.7, get feedback on it, roll it into all relevant commands in 1.8 with any enhancements we might do based on the feedback, and market it as a full-blown feature then. This works out really well, actually.
coffeemug commentedon Jun 29, 2013
I created an issue for it -- #1094.