yegor256 / cactoos

Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons
https://www.cactoos.org
MIT License
737 stars 164 forks source link

"Contains" Predicate #1211

Open StuporHero opened 5 years ago

StuporHero commented 5 years ago

In addition to the Predicates added in #144, it would be nice to have a Predicate that can perform like Collection#contains(Object o). Right now in my project (@paulodamaso, you know because you wrote it), we have a bit of code being introduced that looks like this:

new And(
    user -> {
        user.deactivate();
        user.delete();
    },
    new Filtered<>(
        user ->
        new Or(
            new Filtered<Role>(
                role -> role.getType().equals("SUPER_ADMIN"),
                user.listRoles()
            )
        ).value(),
        this.cli.listUsers()
    )
);

It would be nice if it could look like this:

new And(
    user -> {
        user.deactivate();
        user.delete();
    },
    new Filtered<>(
        user ->
        new Contains<>(
            role -> role.getType().equals("SUPER_ADMIN"),
            user.listRoles()
        ).value(),
        this.cli.listUsers()
    )
);
0crat commented 5 years ago

@paulodamaso/z please, pay attention to this issue

0crat commented 5 years ago

@stuporhero/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!