wemake-services / wemake-services/wemake-python-styleguide

nested higher-order functions

Open
#3,693 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rule request
Dominant language
Python
Stars
2.9k
Forks
430
Avg merge
5h 14m
Merged PRs (30d)
34

Description

Hi! @sobolevn

What do you think about this code:

res = reduce(
    lambda acc, x: acc + x,
    filter(
        lambda x: x > 5,
        map(
            lambda x: x + 1,
            map(
                lambda x: x * 2,
                filter(lambda x: x % 2 == 0, numbers)
            )
        )
    ),
    0
)

How about adding rules to simplify nesting?

It's should be like this:


step1 = filter(lambda x: x % 2 == 0, numbers)
step2 = map(lambda x: x * 2, step1)
step3 = map(lambda x: x + 1, step2)
step4 = filter(lambda x: x > 5, step3)

please, assign me , if you think it should be a violation :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation files or tests are identified. Start by reviewing the project's existing rule conventions and decide whether the nested map, filter, and reduce example defines a precise violation; done requires an agreed rule scope and tests covering the proposed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.