-
Notifications
You must be signed in to change notification settings - Fork 1
Option | extension methods simplifying work #92
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
Open
a-givertzman
wants to merge
52
commits into
master
Choose a base branch
from
Option-extension-methods-simplifying-work
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 fc10e49
Option | extension methods | expect, unwrapOr, unwrapOrElse, unwrapOr
a-givertzman ace72f4
Option | extension methods | extension_extract
a-givertzman 0dd741b
Option | extension methods | extension_extract
a-givertzman 8a34c3e
Option | extension methods | extension_transform
a-givertzman 2f4771f
Package version changed to 2.1.0
a-givertzman aa2d0b6
Package version changed to 2.1.2
a-givertzman 6b0ca4d
Log | fixes
a-givertzman 079691b
Option | extension methods | extension_querying
a-givertzman 4c0c8e2
Option | extension methods | extension_querying
a-givertzman 5265e9e
Merge branch 'master' into Option-extensions-rename, pull changes for…
nyaneet 223b6c1
Option | rename extensions to avoid conflicts
nyaneet e856df8
Option | extensions | renamed
a-givertzman 4cfab43
Merge branch 'Option-extension-methods-simplifying-work' into Option-…
nyaneet b6fab34
Merge pull request #96 from a-givertzman/Option-extensions-rename
a-givertzman 760c265
Log | LogLevel | trace
a-givertzman 0e4c9c9
Log | ConsoleColors fix
a-givertzman 5851c3c
Log | ConsoleColors fix
a-givertzman d60ba95
Log | LogLevel | fixes
a-givertzman 95e4f9b
Log | LogLevel | fixes
a-givertzman 30fcb8d
Log | LogLevel | fixes
a-givertzman b31361c
Localizations | add getters
a-givertzman 27bfe65
Merge pull request #99 from a-givertzman/Localizations-|-add-getters
a-givertzman a28446a
AppSetting | onError
a-givertzman 9ad3f93
AppSetting | onError
a-givertzman fb9eefa
AppSetting | onError
a-givertzman 4a5ec70
Merge pull request #100 from a-givertzman/AppSetting-nullable-or-opti…
a-givertzman 270b85e
colors | Moved colors to hmi_widgets lib
Minyewoo b0c2bc9
pubspec | increased version to 2.1.5
Minyewoo 92fb244
Merge branch 'Option-extension-methods-simplifying-work' into colors-…
Minyewoo 4f2652e
Merge pull request #101 from a-givertzman/colors-removal
Minyewoo 87051c2
JsonMap | add .fromTextFiles constructor
nyaneet feb1ec1
JsonMap | add tests for .fromFile constructor
nyaneet 3b1336c
AppSettings | add writable settings
nyaneet 3f0fe24
Setting | add update method for writable settings
nyaneet 237836a
JsonList | add fromTextFiles constructor
nyaneet 05089b1
JsonMap, JsonList | add tests for each named constructors
nyaneet 385f3d0
AppSettings | add tests for setSetting method
nyaneet 3f879b8
Setting | add tests for update method
nyaneet 76d63e3
pubspec | update package version to 2.1.6
nyaneet 18613e8
AppSettings | rename file parameter
nyaneet c13800b
AppSettings | fix that non-writable settings initialized from store file
nyaneet 630b0c5
AppSettings | fix logging messages
nyaneet c6292a4
AppSettings, Setting | add tests for cases with writable settings
nyaneet 7e6b154
AppSettings | refactor logging, naming, and remove backup on update
nyaneet 886b28a
AppSettings | make sure that saved settings are always taken from run…
nyaneet 76fb7a3
Merge pull request #108 from a-givertzman/AppSettings-add-writable-se…
nyaneet 517b5d5
Failure | child
a-givertzman 774e723
Failure | child
a-givertzman 0db849b
Failure | child
a-givertzman 545288b
Failure | child
a-givertzman c643690
Failure | child
a-givertzman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| // } | ||
| // } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.