fluent icon indicating copy to clipboard operation
fluent copied to clipboard

Automatic unwrapping of _.each

Open dwt opened this issue 4 years ago • 0 comments

@kbauer: I'd like to discuss auto unwrapping seperately - your input is very welcome.

Regarding the auto conversion in map(): I am also constantly annoyed by this, but I am also extremely reluctant to change this, mainly for these reasons:

  1. _.each should behave the same for all the other iterators like .each(), .filter() and friends
  2. _.each should behave consistent in all contexts if possible
_(dict(foo='bar')).call(_.each['foo'])._ == 'bar'
  1. It should be possible to abstract over _.each with .map() and friends. Like this:
_(['foo', 'bar', 'baz']).map(_.each).map(lambda each: each._).map(_.each(print)._)

Now that I think about it, it is really hard to come up with a useful example, where one would want to abstract over _.each with the iterators. Maybe it would be good enough to have an off switch for auto termination that one would have to explicitly set on _.each. Maybe something like _.each._disable_auto_termination() (now that is ugly, but also unlikely to clash with any operation you want to do on _.each)

I am really not sure. I know that it is impossible to really fix _.each auto termination in all circumstances, as you can always wrap in a dict or something to make it invisible to wrapper().

But maybe 'most of the time' is actually good enough to make a difference?

As for a migration, we could start by adding a warning to all wrappers if you hand in a unterminated _.each and ask users to report if they see it. That way we get a feel if there is actual usage of this feature.

dwt avatar Mar 24 '21 20:03 dwt