Skip to content

Add Receiver.take_while and drop_while #354

@llucax

Description

@llucax

What's needed?

Receiver.filter(predicate) is very ambiguous for people not used to functional programming, as it is never clear if the receiver should receive the messages for which predicate(message) returns True or False.

Proposed solution

Add 2 new methods to Receivers:

  • take_while(): Alias for filter().
  • drop_while(): Alias for filter(lambda m: not predicate(m))

We can also consider to deprecate filter() in the future as a way to promote more readable code.

Use cases

No response

Alternatives and workarounds

  • Add a not predicate or filterfalse method: it is more complicated and/or more work.

Additional context

The take/drop while idiom is already very widely used in many languages in conjunction with iterators/streams, like Java, Rust, Ruby and even Python itself offer those in the itertools built-in module.

Metadata

Metadata

Assignees

Labels

part:experimentalAffects the experimental packageresolution:wontfixThis will not be worked ontype:enhancementNew feature or enhancement visitble to users

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions