SinglyLinkedList implements PStack<E> { @Override public boolean anyMatch(Predicate<E> predicate) { SinglyLinkedList<E> c = this; while (c != null) { if (predicate.test(c.element)) { return true; } c = c.next; } return false; } private  SinglyLinkedList(E element); private  SinglyLinkedList(E element, SinglyLinkedList<E> next); @Override PStack<E> push(E e); @Override E peek(); @Override E peek(int i); @Override PStack<E> pop(); @Override boolean isEmpty(); @Override void forEach(Consumer<E> action); @Override boolean anyMatch(Predicate<E> predicate); @Override int size(); @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj);  }
@Test void anyMatch() { PStack<Object> s = PCollections.emptyStack(); Object a = new Object(); Object b = new Object(); assertThat(s.anyMatch(e -> e == a)).isFalse(); assertThat(s.push(a).anyMatch(e -> e == a)).isTrue(); assertThat(s.push(a).push(b).anyMatch(e -> e == a)).isTrue(); Object c = new Object(); assertThat(s.push(a).push(b).anyMatch(e -> e == c)).isFalse(); }