From 83e0b6adbd4971b108fad02fc2e003428f056a2e Mon Sep 17 00:00:00 2001 From: Hugo Pointcheval Date: Thu, 13 Apr 2023 20:19:35 +0200 Subject: [PATCH] feat(type_utils): add nullable num comparison --- .../lib/src/extensions/extensions.dart | 22 ++++++++ .../lib/src/extensions/num_extension.dart | 51 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 packages/wyatt_type_utils/lib/src/extensions/extensions.dart create mode 100644 packages/wyatt_type_utils/lib/src/extensions/num_extension.dart diff --git a/packages/wyatt_type_utils/lib/src/extensions/extensions.dart b/packages/wyatt_type_utils/lib/src/extensions/extensions.dart new file mode 100644 index 00000000..be624333 --- /dev/null +++ b/packages/wyatt_type_utils/lib/src/extensions/extensions.dart @@ -0,0 +1,22 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +export 'date_time_extension.dart'; +export 'encoding.dart'; +export 'iterable_extension.dart'; +export 'num_extension.dart'; +export 'object_extension.dart'; +export 'string_extension.dart'; diff --git a/packages/wyatt_type_utils/lib/src/extensions/num_extension.dart b/packages/wyatt_type_utils/lib/src/extensions/num_extension.dart new file mode 100644 index 00000000..66979260 --- /dev/null +++ b/packages/wyatt_type_utils/lib/src/extensions/num_extension.dart @@ -0,0 +1,51 @@ +// Copyright (C) 2023 WYATT GROUP +// Please see the AUTHORS file for details. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +extension NumExtension on num? { + bool operator <(num? other) { + if (this == null || other == null) { + return false; + } + return this < other; + } + + bool operator >(num? other) { + if (this == null || other == null) { + return false; + } + return this > other; + } + + bool operator <=(num? other) { + if (this == null && other == null) { + return true; + } + if (this == null || other == null) { + return false; + } + return this <= other; + } + + bool operator >=(num? other) { + if (this == null && other == null) { + return true; + } + if (this == null || other == null) { + return false; + } + return this >= other; + } +}