Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3c76fc4
Option | extension methods | unwrap
a-givertzman Nov 6, 2024
fc10e49
Option | extension methods | expect, unwrapOr, unwrapOrElse, unwrapOr
a-givertzman Nov 6, 2024
ace72f4
Option | extension methods | extension_extract
a-givertzman Nov 6, 2024
0dd741b
Option | extension methods | extension_extract
a-givertzman Nov 6, 2024
8a34c3e
Option | extension methods | extension_transform
a-givertzman Nov 7, 2024
2f4771f
Package version changed to 2.1.0
a-givertzman Nov 10, 2024
aa2d0b6
Package version changed to 2.1.2
a-givertzman Nov 10, 2024
6b0ca4d
Log | fixes
a-givertzman Nov 11, 2024
079691b
Option | extension methods | extension_querying
a-givertzman Nov 18, 2024
4c0c8e2
Option | extension methods | extension_querying
a-givertzman Nov 18, 2024
5265e9e
Merge branch 'master' into Option-extensions-rename, pull changes for…
nyaneet Nov 29, 2024
223b6c1
Option | rename extensions to avoid conflicts
nyaneet Nov 29, 2024
e856df8
Option | extensions | renamed
a-givertzman Dec 3, 2024
4cfab43
Merge branch 'Option-extension-methods-simplifying-work' into Option-…
nyaneet Dec 3, 2024
b6fab34
Merge pull request #96 from a-givertzman/Option-extensions-rename
a-givertzman Dec 3, 2024
760c265
Log | LogLevel | trace
a-givertzman Dec 11, 2024
0e4c9c9
Log | ConsoleColors fix
a-givertzman Dec 11, 2024
5851c3c
Log | ConsoleColors fix
a-givertzman Dec 11, 2024
d60ba95
Log | LogLevel | fixes
a-givertzman Dec 11, 2024
95e4f9b
Log | LogLevel | fixes
a-givertzman Dec 11, 2024
30fcb8d
Log | LogLevel | fixes
a-givertzman Dec 11, 2024
b31361c
Localizations | add getters
a-givertzman Dec 12, 2024
27bfe65
Merge pull request #99 from a-givertzman/Localizations-|-add-getters
a-givertzman Dec 12, 2024
a28446a
AppSetting | onError
a-givertzman Dec 13, 2024
9ad3f93
AppSetting | onError
a-givertzman Dec 13, 2024
fb9eefa
AppSetting | onError
a-givertzman Dec 13, 2024
4a5ec70
Merge pull request #100 from a-givertzman/AppSetting-nullable-or-opti…
a-givertzman Dec 13, 2024
270b85e
colors | Moved colors to hmi_widgets lib
Minyewoo Feb 3, 2025
b0c2bc9
pubspec | increased version to 2.1.5
Minyewoo Feb 3, 2025
92fb244
Merge branch 'Option-extension-methods-simplifying-work' into colors-…
Minyewoo Feb 3, 2025
4f2652e
Merge pull request #101 from a-givertzman/colors-removal
Minyewoo Feb 3, 2025
87051c2
JsonMap | add .fromTextFiles constructor
nyaneet Apr 17, 2025
feb1ec1
JsonMap | add tests for .fromFile constructor
nyaneet Apr 17, 2025
3b1336c
AppSettings | add writable settings
nyaneet Apr 17, 2025
3f0fe24
Setting | add update method for writable settings
nyaneet Apr 21, 2025
237836a
JsonList | add fromTextFiles constructor
nyaneet Apr 21, 2025
05089b1
JsonMap, JsonList | add tests for each named constructors
nyaneet Apr 21, 2025
385f3d0
AppSettings | add tests for setSetting method
nyaneet Apr 21, 2025
3f879b8
Setting | add tests for update method
nyaneet Apr 21, 2025
76d63e3
pubspec | update package version to 2.1.6
nyaneet Apr 21, 2025
18613e8
AppSettings | rename file parameter
nyaneet Apr 21, 2025
c13800b
AppSettings | fix that non-writable settings initialized from store file
nyaneet Apr 21, 2025
630b0c5
AppSettings | fix logging messages
nyaneet Apr 21, 2025
c6292a4
AppSettings, Setting | add tests for cases with writable settings
nyaneet Apr 22, 2025
7e6b154
AppSettings | refactor logging, naming, and remove backup on update
nyaneet Apr 22, 2025
886b28a
AppSettings | make sure that saved settings are always taken from run…
nyaneet Apr 22, 2025
76fb7a3
Merge pull request #108 from a-givertzman/AppSettings-add-writable-se…
nyaneet Apr 22, 2025
517b5d5
Failure | child
a-givertzman Jun 25, 2025
774e723
Failure | child
a-givertzman Jun 25, 2025
0db849b
Failure | child
a-givertzman Jun 25, 2025
545288b
Failure | child
a-givertzman Jun 25, 2025
c643690
Failure | child
a-givertzman Jun 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/hmi_core_option.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library hmi_core_option;

export 'src/core/option/option.dart';
export 'src/core/option/option.dart';
export 'src/core/option/extension_extract.dart';
export 'src/core/option/extension_transform.dart';
7 changes: 6 additions & 1 deletion lib/hmi_core_result.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
library hmi_core_result;

export 'src/core/result/result.dart';
export 'src/core/result/result.dart';
export 'src/core/result/extension_adapter.dart';
export 'src/core/result/extension_boolean_operations.dart';
export 'src/core/result/extension_extract.dart';
export 'src/core/result/extension_querying.dart';
export 'src/core/result/extension_transform.dart';
211 changes: 211 additions & 0 deletions lib/src/core/option/extension_extract.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import 'package:hmi_core/hmi_core_failure.dart';
import 'package:hmi_core/hmi_core_option.dart';
///
/// Extracting contained values
extension Extract<V> on Option<V> {
///
/// Returns the contained [Some] value, consuming the `self` value.
///
/// Because this function may panic, its use is generally discouraged.
/// Instead, prefer to use pattern matching and handle the [`None`]
/// case explicitly, or call [`unwrap_or`], [`unwrap_or_else`], or
/// [`unwrap_or_default`].
///
/// [`unwrap_or`]: Option::unwrap_or
/// [`unwrap_or_else`]: Option::unwrap_or_else
/// [`unwrap_or_default`]: Option::unwrap_or_default
///
/// Throws an [Failure] if the self value equals [`None`].
///
/// # Examples
///
/// ```dart
/// final Option<int> x = Ok(2);
/// x.unwrap(); // 2
/// ```
///
/// Should throw a Failure:
/// ```dart
/// final Result<int, String> x = Err("emergency failure");
/// // throw Failure with message: "Called unwrap() on Result with error: emergency failure"
/// x.unwrap();
/// ```
V unwrap() {
return switch (this) {
Some(:final V value) => value,
None() => throw Failure(
message: "Called unwrap() on None",
stackTrace: StackTrace.current,
),
};
}
///
/// Returns the contained [Some] value, consuming the `self` value.
///
/// # Throws an error if the value is a [None] with a custom error message provided by
/// `msg`.
///
/// # Examples
///
/// Basic usage:
///
/// ```dart
/// final Option<int> x = Some(2);
/// x.expect("A custom message"); // 2
/// ```
///
/// Should throw a Failure:
///
/// ```dart
/// final Option<int> x = None();
/// // throw Failure with message: "Testing expect: emergency failure"
/// x.expect("Testing expect");
/// ```
V expect(String message) {
return switch (this) {
Some(:final V value) => value,
None() => throw Failure(
message: message,
stackTrace: StackTrace.current,
),
};
}

// ///
// /// # Examples
// ///
// /// ```dart
// /// final Option<int> = None();
// /// x.unwrapErr(); // "emergency failure"
// /// ```
// ///
// /// Should throw a Failure:
// ///
// /// ```dart
// /// final Result<int, String> x = Ok(2);
// /// // throw Failure with message: "Called unwrapErr() on Result with value: 2"
// /// x.unwrapErr();
// /// ```
// E unwrapErr() {
// return switch (this) {
// Ok(:final V value) => throw Failure(
// message: "Called unwrapErr() on Result with value: $value",
// stackTrace: StackTrace.current,
// ),
// Err(:final E error) => error,
// };
// }
// ///
// /// Returns the contained [Err] error, consuming the `this` value.
// ///
// /// ### Throws an error
// ///
// /// Throws an [Failure] if the value is an [Ok], with a failure message including the
// /// passed message, and the content of the [Ok].
// ///
// ///
// /// ### Examples
// ///
// /// Basic usage:
// /// ```dart
// /// final Result<int, String> x = Err("emergency failure");
// /// x.expectErr("A custom message"); // "emergency failure"
// /// ```
// ///
// /// Should throw a Failure:
// /// ```dart
// /// final Result<int, String> x = Ok(2);
// /// // throw Failure with message: "Testing expectErr: 2"
// /// x.expectErr("Testing expectErr");
// /// ```
// E expectErr(String message) {
// return switch (this) {
// Ok(:final V value) => throw Failure(
// message: "$message: $value",
// stackTrace: StackTrace.current,
// ),
// Err(:final E error) => error,
// };
// }
///
/// Returns the contained [Some] value or a provided default.
///
/// Arguments passed to `unwrap_or` are eagerly evaluated; if you are passing
/// the result of a function call, it is recommended to use [`unwrap_or_else`],
/// which is lazily evaluated.
///
/// ### Examples
///
/// ```dart
/// final defaultValue = 2;
/// final Option<int> x = Some(9);
/// x.unwrapOr(defaultValue); // 9
/// //
/// final Option<int> y = None();
/// y.unwrapOr(defaultValue); // 2
/// ```
V unwrapOr(V d) {
return switch (this) {
Some(:final V value) => value,
None() => d,
};
}
///
/// Returns the contained [`Some`] value or computes it from a closure.
///
/// ### Examples
///
/// ```dart
/// int onNone() => 'sNone';
///
/// final Option<int> x = Some('isSome');
/// x.unwrapOrElse(onNone); // 'isSome'
///
/// final Option<int> y = None();
/// y.unwrapOrElse(onNone); // 'isNone'
/// ```
V unwrapOrElse(V Function() d) {
return switch (this) {
Some(:final V value) => value,
None() => d(),
};
}
}
// ///
// /// Extracting contained values for [Ok]
// extension ExtractOk<V> on Result<V, Never> {
// ///
// /// Returns the contained [Ok] value, but never throw an error.
// ///
// /// It can be used as a maintainability safeguard that will fail
// /// to compile if the error type of the [Result] is later changed
// /// from [Never] to a type that can actually occur.
// ///
// /// ### Examples
// /// ```dart
// /// Result<String, Never> onlyGoodNews() => Ok("this is fine");
// /// onlyGoodNews().intoOk(); // "this is fine"
// /// ```
// V intoOk() {
// return (this as Ok).value;
// }
// }
// ///
// /// Extracting contained values for [Err]
// extension ExtractErr<E> on Result<Never, E> {
// ///
// /// Returns the contained [Err] value, but never throw an error.
// ///
// /// It can be used as a maintainability safeguard that will fail
// /// to compile if the ok type of the [Result] is later changed
// /// from [Never] to a type that can actually occur.
// ///
// /// ### Examples
// /// ```dart
// /// Result<String, Never> onlyBadNews() => Err("Oops, it failed");
// /// onlyBadNews().intoErr(); // "Oops, it failed"
// /// ```
// E intoErr() {
// return (this as Err).error;
// }
// }
35 changes: 35 additions & 0 deletions lib/src/core/option/extension_transform.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:hmi_core/hmi_core_option.dart';
import 'package:hmi_core/hmi_core_result.dart';

///
/// Transforming contained values
extension Transform<V, E> on Option<V> {
///
/// Transforms the `Option<T>` into a [Result<T, E>],
/// mapping [Some(v)] to [Ok(v)] and [None] to [Err(err)].
///
/// Arguments passed to `ok_or` are eagerly evaluated; if you are passing the
/// result of a function call, it is recommended to use [`ok_or_else`], which is
/// lazily evaluated.
///
/// [`Ok(v)`]: Ok
/// [`Err(err)`]: Err
/// [`Some(v)`]: Some
/// [`ok_or_else`]: Option::ok_or_else
///
/// # Examples
///
/// ```
/// let x = Some("foo");
/// assert_eq!(x.ok_or(0), Ok("foo"));
///
/// let x: Option<&str> = None;
/// assert_eq!(x.ok_or(0), Err(0));
/// ```
Result<V, E> okOr(E err) {
return switch (this) {
Some(:final value) => Ok(value),
None() => Err(err),
};
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: hmi_core
description: A Flutter core package of hmi_widgets package which is helps to visualize states, values, changes and other artefacts from technological processes.
version: 2.0.0
version: 2.1.2
homepage: https://github.com/a-givertzman/hmi_core

environment:
Expand Down