#valueWithPossibleArgument: vs. #cull:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

#valueWithPossibleArgument: vs. #cull:

marcel.taeumel
Hi, there.

I think that all (6) sends in Trunk to #valueWithPossibleArgument: can be replaced with #cull:, which is more flexible.


Does anyone recall the story of #cull:? Maybe we should just implement #valueWithPossibleArgument: on MessageSend (and maybe Symbol) to make it more consistent?

For context, here is how I stumbled on it:
#(1 2 3) collect: #even. "Works." 
1 ifNotNil: #even. "Works."
#(1) ifNotEmpty: #first. "Does not work."

Please note that this question is not about "#(1 2 3) collect: #even" versus "#(1 2 3) collect: [:ea | ea even]". ;-) This is more like a case of surprising inconsistency...

Best,
Marcel


Reply | Threaded
Open this post in threaded view
|

Re: #valueWithPossibleArgument: vs. #cull:

Nicolas Cellier
I think that cull: is cross-dialect, maybe born in VW (Travis Griggs?)

Le lun. 20 mai 2019 à 17:38, Marcel Taeumel <[hidden email]> a écrit :
Hi, there.

I think that all (6) sends in Trunk to #valueWithPossibleArgument: can be replaced with #cull:, which is more flexible.


Does anyone recall the story of #cull:? Maybe we should just implement #valueWithPossibleArgument: on MessageSend (and maybe Symbol) to make it more consistent?

For context, here is how I stumbled on it:
#(1 2 3) collect: #even. "Works." 
1 ifNotNil: #even. "Works."
#(1) ifNotEmpty: #first. "Does not work."

Please note that this question is not about "#(1 2 3) collect: #even" versus "#(1 2 3) collect: [:ea | ea even]". ;-) This is more like a case of surprising inconsistency...

Best,
Marcel




image.png (27K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: #valueWithPossibleArgument: vs. #cull:

Chris Muller-3
In reply to this post by marcel.taeumel

Hi, there.

I think that all (6) sends in Trunk to #valueWithPossibleArgument: can be replaced with #cull:, which is more flexible.

It may be that these replacements can occur in trunk, but please don't let it lead to, "ah, now valueWithPossibleArgument: has no senders so we can deprecate it."   ;-/

For arguments that accept a Collection, coercing a single object into a single-element collection is a useful pattern for improving API usability.  #valueWithPossibleArgument: does that.


 


Does anyone recall the story of #cull:? Maybe we should just implement #valueWithPossibleArgument: on MessageSend (and maybe Symbol) to make it more consistent?

+1.  We should add #valueWithPossibleArgument: to MessageSend (and maybe Symbol), and keep it on BlockClosure too.  It is useful separately from #cull:[...] for certain situations.

Best,
  Chris
 

For context, here is how I stumbled on it:
#(1 2 3) collect: #even. "Works." 
1 ifNotNil: #even. "Works."
#(1) ifNotEmpty: #first. "Does not work."

Please note that this question is not about "#(1 2 3) collect: #even" versus "#(1 2 3) collect: [:ea | ea even]". ;-) This is more like a case of surprising inconsistency...

Best,
Marcel



Reply | Threaded
Open this post in threaded view
|

Re: #valueWithPossibleArgument: vs. #cull:

Nicolas Cellier


Le lun. 20 mai 2019 à 21:19, Chris Muller <[hidden email]> a écrit :

Hi, there.

I think that all (6) sends in Trunk to #valueWithPossibleArgument: can be replaced with #cull:, which is more flexible.

It may be that these replacements can occur in trunk, but please don't let it lead to, "ah, now valueWithPossibleArgument: has no senders so we can deprecate it."   ;-/

For arguments that accept a Collection, coercing a single object into a single-element collection is a useful pattern for improving API usability.  #valueWithPossibleArgument: does that.


 


Does anyone recall the story of #cull:? Maybe we should just implement #valueWithPossibleArgument: on MessageSend (and maybe Symbol) to make it more consistent?

+1.  We should add #valueWithPossibleArgument: to MessageSend (and maybe Symbol), and keep it on BlockClosure too.  It is useful separately from #cull:[...] for certain situations.

Best,
  Chris
 
valueWithPossibleArgument: does one thing more than cull:
it fill missing arguments with nil
I don't know if this is super useful... I find the feature questionable personnally.
Anyway, no sender is using this feature, so all senders could rather use cull:

valueWithPossibleArgs: has no equivalent because no cull message takes an Array of arguments.
valueWithPossibleArgs: is already understood by MessageSend while valueWithPossibleArgument: is not which is somehow surprising.

I'm not sure at all that these two selectors would be good to add to Symbol.
For example, Symbol only understand cull: but not cull:cull: nor does it understand valueWithArguments:



For context, here is how I stumbled on it:
#(1 2 3) collect: #even. "Works." 
1 ifNotNil: #even. "Works."
#(1) ifNotEmpty: #first. "Does not work."

Please note that this question is not about "#(1 2 3) collect: #even" versus "#(1 2 3) collect: [:ea | ea even]". ;-) This is more like a case of surprising inconsistency...

Best,
Marcel