docs(type_utils): add some documentation

This commit is contained in:
Hugo Pointcheval 2023-04-13 16:45:18 +02:00
parent 84b17382c1
commit 7a3de79e36
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
4 changed files with 52 additions and 49 deletions

View File

@ -1,5 +1,5 @@
<!--
* Copyright (C) 2022 WYATT GROUP
* Copyright (C) 2023 WYATT GROUP
* Please see the AUTHORS file for details.
* This program is free software: you can redistribute it and/or modify
@ -7,7 +7,7 @@
* 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,
* 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.
@ -16,18 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
# Dart - Wyatt Type Utils
<p align="left">
<a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis">
<img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" />
</a>
<a href="https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_analysis"><img src="https://img.shields.io/badge/Style-Wyatt%20Analysis-blue.svg?style=flat-square" alt="Style: Wyatt Analysis" /></a>
<img src="https://img.shields.io/badge/SDK-Dart%20%7C%20Flutter-blue?style=flat-square" alt="SDK: Dart & Flutter" />
</p>
Type Utils for Dart & Flutter.
Either, Option and other useful types and extensions for Dart (and Flutter).
## Option\<T>
@ -62,8 +58,8 @@ print('`rand` contains 10 ? => ${rand.contains(10)}');
*E.g. null reference exception or index out of bounds are not related to domain - they rather indicate a defect.*
Either is defined as a generic type with two branches
- success with **T**
- failure with **E**
* success with **T**
* failure with **E**
It can appear in two forms, where it contains an object of **Ok**, or where it contains an object of **Err**. It cannot appear in both states at once, or in none of them. Therefore, if one possesses an **Result** instance, it either contains a successfully produced result, or contains an error object.
@ -95,20 +91,20 @@ print(myList); // prints '[42, 16]'
This package also provides extensions for Dart types.
- Object
- isNull
- isNotNull
- log
- Iterable
- isNullOrEmpty
- isNotNullOrEmpty
- For bytes iterables
* Object
+ isNull
+ isNotNull
+ log
* Iterable
+ isNullOrEmpty
+ isNotNullOrEmpty
+ For bytes iterables
- toTypedList
- toStr
- String
- isNullOrEmpty
- isNotNullOrEmpty
- toBytes
* String
+ isNullOrEmpty
+ isNotNullOrEmpty
+ toBytes
String 🔁 Uint8List works with encoding:
@ -118,27 +114,27 @@ final Uint8List bytes = myString.toBytes(from : Encoding.utf16);
print(bytes.toStr(to : Encoding.utf16)); // prints 'abc'
```
- DateTime
- fromSecondsSinceEpoch
- secondsSinceEpoch
- timestamp
- tomorrow
- yesterday
- today
- add/sub/set
- nextDay
- previousDay
- nextMonth
- previousMonth
- nextYear
- previousYear
- nextWeek
- previousWeek
- isFuture
- isPast
- isLeapYear
- format
- operators
* DateTime
+ fromSecondsSinceEpoch
+ secondsSinceEpoch
+ timestamp
+ tomorrow
+ yesterday
+ today
+ add/sub/set
+ nextDay
+ previousDay
+ nextMonth
+ previousMonth
+ nextYear
+ previousYear
+ nextWeek
+ previousWeek
+ isFuture
+ isPast
+ isLeapYear
+ format
+ operators
The date formatter works with `String` formatter:

View File

@ -171,8 +171,11 @@ abstract class Option<T> extends _EitherBase<T, void> {
}
}
/// {@template value}
/// Contains the non-null value of the [Option].
/// {@endtemplate}
class Value<T> extends Option<T> with _Left<T, void> {
/// {@macro ok}
/// {@macro value}
const Value(this.value) : super._();
final T value;
@ -236,8 +239,11 @@ class Value<T> extends Option<T> with _Left<T, void> {
_EitherBase<T, F> _or<F>(_EitherBase<T, F> res) => this as _EitherBase<T, F>;
}
/// {@template none}
/// Contains no value.
/// {@endtemplate}
class None<T> extends Option<T> with _Right<T, void> {
/// {@macro ok}
/// {@macro none}
const None() : super._();
@override

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/// Defines different text encoding types.
enum Encoding {
utf8,
utf16,

View File

@ -1,16 +1,16 @@
name: wyatt_type_utils
description: Either, Option and other useful types.
description: Either, Option and other useful types and extensions.
repository: https://git.wyatt-studio.fr/Wyatt-FOSS/wyatt-packages/src/branch/master/packages/wyatt_type_utils
version: 0.0.4
publish_to: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
environment:
sdk: '>=2.17.0 <3.0.0'
sdk: ">=2.17.0 <3.0.0"
dev_dependencies:
test: ^1.22.0
wyatt_analysis:
hosted: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub
version: ^2.4.1
version: ^2.4.1