transform<S> method

Optional<S> transform<S>(
  1. S transformer(
    1. T value
    )
)

Transforms the Optional value.

If the Optional is absent(), returns absent() without applying the transformer.

The transformer must not return null. If it does, an ArgumentError is thrown.

Implementation

Optional<S> transform<S>(S Function(T value) transformer) {
  return _value == null
      ? Optional<S>.absent()
      : Optional<S>.of(transformer(_value!));
}