Class Or

  • All Implemented Interfaces:
    Scalar<Boolean>

    public final class Or
    extends Object
    implements Scalar<Boolean>
    Logical disjunction. This class performs short-circuit evaluation in which arguments are executed only if the preceding argument does not suffice to determine the value of the expression.

    This class can be effectively used to iterate through a collection, just like Stream.forEach(java.util.function.Consumer) works:

    new Or( new ProcOf<>(input -> System.out.printf("\'%s\' ", input) ), new IterableOf<>("Mary", "John", "William", "Napkin") ).value(); // will print 'Mary' 'John' 'William' 'Napkin' to standard output // the result of this operation is always false

    This class could be also used for matching multiple boolean expressions:

    new Or( new False(), new True(), new True() ).value(); // the result is true new Or( new False(), new False(), new False() ).value(); // the result is false

    There is no thread-safety guarantee.

    This class implements Scalar, which throws a checked Exception. This may not be convenient in many cases. To make it more convenient and get rid of the checked exception you can use the Unchecked decorator. Or you may use IoChecked to wrap it in an IOException.

    Since:
    0.8
    • Constructor Detail

      • Or

        @SafeVarargs
        public Or​(Proc<? super X> proc,
                  X... src)
        Ctor.
        Type Parameters:
        X - Type of items in the iterable
        Parameters:
        proc - Proc to map
        src - The iterable
      • Or

        @SafeVarargs
        public Or​(Func<? super X,​Boolean> func,
                  X... src)
        Ctor.
        Type Parameters:
        X - Type of items in the iterable
        Parameters:
        func - Func to map
        src - The iterable
      • Or

        public Or​(Proc<? super X> proc,
                  Iterable<? extends X> src)
        Ctor.
        Type Parameters:
        X - Type of items in the iterable
        Parameters:
        proc - Proc to use
        src - The iterable
        Since:
        0.24
      • Or

        public Or​(Func<? super X,​Boolean> func,
                  Iterable<? extends X> src)
        Ctor.
        Type Parameters:
        X - Type of items in the iterable
        Parameters:
        func - Func to map
        src - The iterable
      • Or

        @SafeVarargs
        public Or​(X subject,
                  Func<? super X,​Boolean>... conditions)
        Ctor.
        Type Parameters:
        X - Type of items in the iterable
        Parameters:
        subject - The subject
        conditions - Funcs to map
      • Or

        public Or​(Iterable<? extends Scalar<Boolean>> iterable)
        Ctor.
        Parameters:
        iterable - The iterable.