isPresent method

bool isPresent()

If a value is present, returns true, otherwise false.

Returns true if a value is present, otherwise false.

Example

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

print(name.isPresent()); // true
print(empty.isPresent()); // false

// Common usage pattern
if (name.isPresent()) {
  print("Name is: ${name.get()}");
}

Implementation

bool isPresent() {
  return _value != null;
}