# orElseGet method

T orElseGet([

1. T supplier()?

])

If a value is present, returns the value, otherwise returns the result produced by the supplying function.

`supplier` the supplying function that produces a value to be returned

Returns the value, if present, otherwise the result produced by the supplying function.

Throws InvalidArgumentException if no value is present and the supplying function is null.

## Example

    Optional<String> name = Optional.of("Kate");
    Optional<String> empty = Optional.empty();

    print(name.orElseGet(() => "Generated")); // "Kate"
    print(empty.orElseGet(() => "Generated")); // "Generated"

    // Lazy evaluation - supplier only called when needed
    String expensiveDefault() {
      print("Computing expensive default...");
      return "expensive result";
    }

    print(name.orElseGet(expensiveDefault)); // "Kate" (no print)
    print(empty.orElseGet(expensiveDefault)); // "expensive result" (prints message)

    // Useful for expensive computations
    Optional<List<String>> cachedData = Optional.empty();
    List<String> data = cachedData.orElseGet(() => loadDataFromDatabase());

    // With random values
    import 'dart:math';
    Random random = Random();
    Optional<int> maybeNumber = Optional.empty();
    int number = maybeNumber.orElseGet(() => random.nextInt(100));

## Implementation

    T orElseGet([T Function()? supplier]) {
      if (supplier == null) {
        throw InvalidArgumentException('supplier cannot be null');
      }
      return _value != null ? _value as T : supplier();
    }