From 24761da890cd2f2d9f7f61c465d491a52eab8a39 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 10 Jul 2023 22:18:18 +0200 Subject: [PATCH] Change definition to class `Optional` This excludes nullable types from being able to be put into an Optional, which is confusing. --- lib/src/core/optional.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/src/core/optional.dart b/lib/src/core/optional.dart index 6784ee56..e75675ad 100644 --- a/lib/src/core/optional.dart +++ b/lib/src/core/optional.dart @@ -36,7 +36,7 @@ import 'dart:collection'; /// /// Both of these should be very rare. @Deprecated('Generally, migrate to a nullable type.') -class Optional extends IterableBase { +class Optional extends IterableBase { /// Constructs an empty Optional. const Optional.absent() : _value = null; @@ -103,7 +103,7 @@ class Optional extends IterableBase { /// 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 transform(S Function(T value) transformer) { + Optional transform(S Function(T value) transformer) { return _value == null ? Optional.absent() : Optional.of(transformer(_value!)); @@ -114,7 +114,8 @@ class Optional extends IterableBase { /// If the Optional is [absent()], returns [absent()] without applying the transformer. /// /// Returns [absent()] if the transformer returns `null`. - Optional transformNullable(S? Function(T value) transformer) { + Optional transformNullable( + S? Function(T value) transformer) { return _value == null ? Optional.absent() : Optional.fromNullable(transformer(_value!));