code: public static <E, R> Stream<R> validate(Stream<E> stream, Predicate<? super E> validator,
                                              Function<? super E, ? extends R> transformingIfValid, Function<? super E, ? extends R> transformingIfNotValid) {
          Objects.requireNonNull(stream);
          Objects.requireNonNull(validator);
          Objects.requireNonNull(transformingIfValid);
          Objects.requireNonNull(transformingIfNotValid);
  
          ValidatingSpliterator.Builder<E, R> builder = new ValidatingSpliterator.Builder<>();
          ValidatingSpliterator<E, R> spliterator = builder.with(stream.spliterator())
                  .validatedBy(validator)
                  .withValidFunction(transformingIfValid)
                  .withNotValidFunction(transformingIfNotValid)
                  .build();
          return StreamSupport.stream(spliterator, stream.isParallel()).onClose(stream::close);
      }
docs: <p>Generates a stream by validating the elements of an input stream one by one using the provided predicate. </p>
  <p>An element of the input stream is said to be valid if the provided predicate returns true for this element.</p>
  <p>A valid element is replaced in the returned stream by the application of the provided function for valid
  elements. A non-valid element is replaced by the other function. </p>
  <p>A <code>NullPointerException</code> will be thrown if one of the provided elements is null. </p>
  
  @param stream                 the stream to be validated. Will throw a <code>NullPointerException</code> if <code>null</code>.
  @param validator              the predicate used to validate the elements of the stream.
  Will throw a <code>NullPointerException</code> if <code>null</code>.
  @param transformingIfValid    the function applied to the valid elements.
  Will throw a <code>NullPointerException</code> if <code>null</code>.
  @param transformingIfNotValid the function applied to the non-valid elements.
  Will throw a <code>NullPointerException</code> if <code>null</code>.
  @param <E>                    the type of the elements of the input stream.
  @param <R>                    the type of the elements of the returned stream.
  @return the validated and transformed stream.