8bitme / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

Suggestion: exists() #64

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I would suggest adding an exists() method to the main class, with the following 
simple implementation:
  public static boolean exists(Matcher<?> matcher, Object iterable) {
    return selectFirst(iterable, matcher) != null;
  }

Here are some tests

    assertTrue("Anything", exists(anything(), Collections.singleton("foo")));
    assertFalse("Nothing", exists(not(anything()), Collections.singleton("foo")));
    assertFalse("Empty", exists(anything(), Collections.emptySet()));

    assertTrue("Has match", exists(equalTo("foo"), Collections.singleton("foo")));
    assertFalse("Has no match", exists(equalTo("foo"), Collections.singleton("bar")));
    assertTrue("One of many", exists(equalTo("foo"), Arrays.asList("bar", "foo")));

Original issue reported on code.google.com by mattias....@gmail.com on 15 Apr 2011 at 12:07

GoogleCodeExporter commented 9 years ago
Implemented in version 2.3.3

Original comment by mario.fu...@gmail.com on 22 Apr 2011 at 9:04