code: public static <S,T> Optional<T> collect(Optional<S> self, @ClosureParams(FirstParam.FirstGenericType.class) Closure<T> transform) {
          Objects.requireNonNull(self);
          Objects.requireNonNull(transform);
          if (!self.isPresent()) {
              return self.empty();
          }
          return Optional.ofNullable(transform.call(self.get()));
      }
docs: If the optional contains a value, returns an optional containing the transformed value obtained using the <code>transform</code> closure
  or otherwise an empty optional.
  <pre class="groovyTestCase">
  assert Optional.of("foobar").collect{ it.size() }.get() == 6
  assert !Optional.empty().collect{ it.size() }.isPresent()
  </pre>
  
  @param self      an Optional
  @param transform the closure used to transform the optional value if present
  @return an Optional containing the transformed value or empty if the optional is empty or the transform returns null