Skip to content

Implement Predicate<T>  #98

Closed
Closed

Description

@amarpotghan

many times I ended up in writing following combinators, I think it would add some value if library has it :

  1. F<A, Bool> and(F<A, Bool> pred1, F<A, Bool> pred2)
  2. F<A, Bool> or(F<A, Bool> pred1, F<A, Bool> pred2)
  3. F < B, Bool > comap(F<B, A>, F<A, Bool>)
  4. F<B, Bool> notFor(F<B, A>, F<A, Bool>) [a la Haskell's Data.Function.Predicate's isn't]
  5. F<A, Bool> inverse(F<A, Bool>)

additionally we could add:
nand, nor, xor
We can also implement Predicate2<A, B>, Predicate3<A, B, C> and so on.
thoughts?

Activity

  1. mperry commented on Jan 28, 2015

    @mperry
    Contributor

    I think we need these, the closest thing I can see is in the Booleans class (e.g. Booleans.not), so perhaps that is the best place to add these.

    Personally, I don't think we need a Predicate class and related arities. Given Java uses nominative typing I think conversion is a pain and would have few advantages.

    I would encourage you to do this and submit a pull request.

  2. amarpotghan commented on Jan 28, 2015

    @amarpotghan
    ContributorAuthor

    Now as I see through Booleans, definitely we don't need Predicates.

  3. techtangents commented on Jan 28, 2015

    @techtangents

    I would also advise against a Predicate type. We had one in our fj
    equivalent, and removed it. It was just a hassle, and no benefit over
    simply writing F<A, Boolean>.

    The 'and', 'or' etc functions for F<A, Boolean> are reasonable, though.

    F<A, Boolean> forms 2 Moniods, one over 'and', one over 'or'. The 'or'
    variant is also an Alternative.

    F<A, Boolean> or(List<F<A, Boolean>> fs) {...}
    F<A, Boolean> and(List<F<A, Boolean>> fs) {...}

    Amar mailto:notifications@github.com
    28 January 2015 10:59 pm

    Now as I see through |Booleans|, definitely we don't need Predicates.

    —
    Reply to this email directly or view it on GitHub
    #98 (comment).

    Amar mailto:notifications@github.com
    27 January 2015 7:26 pm

    many times I ended up in writing following combinators, I think it
    would add some value if library has it :

    1. F and(F pred1, F pred2)
    2. F or(F pred1, F pred2)
    3. F_comap(F_, F)**
    4. F_notFor(F_, F) [a la Haskell's Data.Function.Predicate's |isn't|]**
    5. F inverse(F)

    additionally we could add:
    nand, nor, xor
    We can also implement Predicate2, Predicate3 and so on.
    thoughts?

    —
    Reply to this email directly or view it on GitHub
    #98.

  4. amarpotghan commented on Jan 30, 2015

    @amarpotghan
    ContributorAuthor

    @techtangents every function F<A, B> should form a monoid if B is monoid. Is my understanding correct?

  5. techtangents commented on Jan 30, 2015

    @techtangents

    Sounds right to me.

    Amar mailto:notifications@github.com
    31 January 2015 2:51 am

    @techtangents https://github.com/techtangents every function F
    should form a monoid if B is monoid. Is my understanding correct?

    —
    Reply to this email directly or view it on GitHub
    #98 (comment).

    Amar mailto:notifications@github.com
    27 January 2015 7:26 pm

    many times I ended up in writing following combinators, I think it
    would add some value if library has it :

    1. F and(F pred1, F pred2)
    2. F or(F pred1, F pred2)
    3. F_comap(F_, F)**
    4. F_notFor(F_, F) [a la Haskell's Data.Function.Predicate's |isn't|]**
    5. F inverse(F)

    additionally we could add:
    nand, nor, xor
    We can also implement Predicate2, Predicate3 and so on.
    thoughts?

    —
    Reply to this email directly or view it on GitHub
    #98.

  6. mperry commented on Feb 7, 2015

    @mperry
    Contributor

    This is addressed in PR #102.

  7. added this to the None milestone on Jul 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions