Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert change to Optional #712

Merged
merged 1 commit into from Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,5 @@
#### 3.2.0-dev

* Explicitly disallow a `nullable` type argument for `Optional`.
* Expose `TreeIterator` for iterating `TreeSet` instead of using
`BidirectionalIterator`.
* Require Dart 2.17
Expand Down
9 changes: 5 additions & 4 deletions lib/src/core/optional.dart
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: null_check_on_nullable_type_parameter

import 'dart:collection';

/// A value that might be absent.
Expand All @@ -23,7 +25,7 @@ import 'dart:collection';
/// 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?`.
class Optional<T extends Object> extends IterableBase<T> {
class Optional<T> extends IterableBase<T> {
/// Constructs an empty Optional.
const Optional.absent() : _value = null;

Expand Down Expand Up @@ -90,7 +92,7 @@ class Optional<T extends Object> extends IterableBase<T> {
/// If the Optional is [absent()], returns [absent()] without applying the transformer.
///
/// The transformer must not return [null]. If it does, an [ArgumentError] is thrown.
Optional<S> transform<S extends Object>(S Function(T value) transformer) {
Optional<S> transform<S>(S Function(T value) transformer) {
return _value == null
? Optional<S>.absent()
: Optional<S>.of(transformer(_value!));
Expand All @@ -101,8 +103,7 @@ class Optional<T extends Object> extends IterableBase<T> {
/// If the Optional is [absent()], returns [absent()] without applying the transformer.
///
/// Returns [absent()] if the transformer returns [null].
Optional<S> transformNullable<S extends Object>(
S? Function(T value) transformer) {
Optional<S> transformNullable<S>(S? Function(T value) transformer) {
return _value == null
? Optional<S>.absent()
: Optional<S>.fromNullable(transformer(_value!));
Expand Down