Quantifiers, exactly and only #518

Closed
wants to merge 6 commits into
from

3 participants

@joshdk

Currently, underscore implements two different quantifiers;

  • The universal quantifier _.all, "do all elements pass a truth test?".
  • The existential quantifier _.any, "do any elements pass a truth test?".

This for aims to add two more quantifiers;

  • An exact quantifier _.exactly, "do exactly n elements pass a truth test?".
  • The uniqueness quantifier ∃! _.only, "does only one element pass a truth test?". This is a specific case of exactly, where n is 1.
joshdk added some commits Mar 17, 2012
@joshdk joshdk Added an _.exactly quantifier
- Similar to _.any and _.all, _.exactly returns true if an exact number of elements pass a truth test.
c75dee8
@joshdk joshdk Covered condition when obj was null
- If obj is null, and count is 0, yield true.
b44aacb
@joshdk joshdk Added testing functions for _.exactly 662e110
@joshdk joshdk Merge remote-tracking branch 'upstream/master' into quantifier-exactly 003c53c
@joshdk joshdk Added an _.only quantifier
- Used for determining of only 1 element passes a truth test.
5e777ad
@joshdk joshdk Added tests for _.only 6c6da43
@jashkenas
Owner

The goal of Underscore isn't to provide every logical predicate under the sun, but rather the useful ones.

Got any real-world code handy with use cases for when you've needed these?

@jashkenas
Owner

Looks like that's a "no".

@jashkenas jashkenas closed this Apr 2, 2012
@arbales

(But, @joshdk — since you wrote them and you'd use them, they'd probably make a great underscore.predicates.js)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment