Skip to content

Commit

Permalink
Add more detailed guidance to Optional dartdoc. (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmorgan authored Jun 8, 2023
1 parent 67ea710 commit 129d8b6
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/src/core/optional.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ import 'dart:collection';

/// A value that might be absent.
///
/// Use Optional as an alternative to allowing fields, parameters or return
/// values to be null. It signals that a value is not required and provides
/// convenience methods for dealing with the absent case.
/// This class was written before Dart SDK 2.12 added first class support for
/// non-nullable types. Where possible, it is strongly preferred to use those
/// language features and to not use this class at all.
///
/// With the introduction of non-null by default in Dart SDK 2.12, developers
/// should avoid adding more uses of this type. Existing users should migrate
/// away from the `Optional` type to types marked nullable: `T?`.
/// Usually, `Optional<T>` should be migrated to `T?`.
///
/// There are a small number of cases where this is the appropriate abstraction
/// and we therefore do not intend on removing this type.
/// However, code that already uses `Optional` can continue to use it if the
/// cost of migration is considered too high. The class will not be removed.
///
/// Valid new use cases:
///
/// - if an API only accepts non-null values, you can use `Optional` as a
/// general way to pass it values that mean "absent";
/// - for a general way to represent "nested levels" of absent, such as
/// `Optional<Optional<T>>`.
///
/// Both of these should be very rare.
@Deprecated('Generally, migrate to a nullable type.')
class Optional<T> extends IterableBase<T> {
/// Constructs an empty Optional.
Expand Down

0 comments on commit 129d8b6

Please sign in to comment.