Skip to content

Commit 5404317

Browse files
Change type name Maybe to Option [Some/None]
1 parent bdbb318 commit 5404317

26 files changed

+1150
-1148
lines changed

.packages

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# For more info see: https://dart.dev/go/dot-packages-deprecation
55
#
6-
# Generated by pub on 2021-06-13 09:41:57.111321.
6+
# Generated by pub on 2021-06-13 21:30:13.314180.
77
_fe_analyzer_shared:file:///C:/Users/Sandro%20Maglione/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/_fe_analyzer_shared-22.0.0/lib/
88
analyzer:file:///C:/Users/Sandro%20Maglione/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/analyzer-1.7.0/lib/
99
args:file:///C:/Users/Sandro%20Maglione/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/args-2.1.0/lib/

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v0.0.3 - 13 June 2021
2+
3+
- Changed name of type `Maybe` to `Option` to be inline with fp-ts, cats, and dartz [**BREAKING CHANGE**]
4+
15
# v0.0.2 - 13 June 2021
26

37
First major release:

README.md

+24-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<img src="https://img.shields.io/github/stars/SandroMaglione/fpdart?logo=github" />
66
</a>
77
<img src="https://img.shields.io/github/license/SandroMaglione/fpdart?logo=github" />
8-
<img src="https://img.shields.io/badge/version-0.0.2-blue.svg" />
8+
<img src="https://img.shields.io/badge/version-0.0.3-blue.svg" />
99
<!-- <img src="https://img.shields.io/badge/flutter-v2.0.2-blue.svg" /> -->
1010
<img src="https://img.shields.io/badge/dart-v2.13.1-blue.svg" />
1111
<a href="https://github.com/SandroMaglione">
@@ -30,7 +30,7 @@ Fpdart is inspired by [fp-ts](https://gcanti.github.io/fp-ts/), [cats](https://t
3030

3131
## Types
3232

33-
- [x] `Maybe` (`Option`)
33+
- [x] `Option`
3434
- [x] `Either`
3535
- [x] `Unit`
3636
- [x] `Task`
@@ -43,7 +43,7 @@ Fpdart is inspired by [fp-ts](https://gcanti.github.io/fp-ts/), [cats](https://t
4343
- [ ] `IOEither`
4444
- [ ] `Writer`
4545
- [ ] `Lens`
46-
- [ ] `TaskMaybe`
46+
- [ ] `TaskOption`
4747
- [ ] `ReaderEither`
4848
- [ ] `ReaderTask`
4949
- [ ] `ReaderTaskEither`
@@ -54,40 +54,40 @@ Fpdart is inspired by [fp-ts](https://gcanti.github.io/fp-ts/), [cats](https://t
5454
```yaml
5555
# pubspec.yaml
5656
dependencies:
57-
fpdart: ^0.0.2 # Check out the latest version
57+
fpdart: ^0.0.3 # Check out the latest version
5858
```
5959
6060
## Examples
6161
62-
### [Maybe](https://github.com/SandroMaglione/fpdart/blob/9da7cae3b9f9dc690ff3255004393c4b979183e9/lib/src/maybe.dart#L40)
62+
### [Option](https://github.com/SandroMaglione/fpdart/blob/9da7cae3b9f9dc690ff3255004393c4b979183e9/lib/src/option.dart#L40)
6363
6464
```dart
65-
/// Create an instance of [Just]
66-
final maybe = Maybe.of(10);
65+
/// Create an instance of [Some]
66+
final option = Option.of(10);
6767

68-
/// Create an instance of [Nothing]
69-
final nothing = Maybe<int>.nothing();
68+
/// Create an instance of [None]
69+
final none = Option<int>.none();
7070

7171
/// Map [int] to [String]
72-
final map = maybe.map((a) => '$a');
72+
final map = option.map((a) => '$a');
7373

74-
/// Extract the value from [Maybe]
75-
final value = maybe.getOrElse(() => -1);
74+
/// Extract the value from [Option]
75+
final value = option.getOrElse(() => -1);
7676

7777
/// Pattern matching
78-
final match = maybe.match(
79-
(just) => print('Just($just)'),
80-
() => print('Nothing'),
78+
final match = option.match(
79+
(a) => print('Some($a)'),
80+
() => print('None'),
8181
);
8282

8383
/// Convert to [Either]
84-
final either = maybe.toEither(() => 'missing');
84+
final either = option.toEither(() => 'missing');
8585

8686
/// Chain computations
87-
final flatMap = maybe.flatMap((a) => Maybe.of(a + 10));
87+
final flatMap = option.flatMap((a) => Option.of(a + 10));
8888

89-
/// Return [Nothing] if the function throws an error
90-
final tryCatch = Maybe.tryCatch(() => int.parse('invalid'));
89+
/// Return [None] if the function throws an error
90+
final tryCatch = Option.tryCatch(() => int.parse('invalid'));
9191
```
9292

9393
### [Either](https://github.com/SandroMaglione/fpdart/blob/9da7cae3b9f9dc690ff3255004393c4b979183e9/lib/src/either.dart#L16)
@@ -124,8 +124,8 @@ final match = right.match(
124124
(r) => print('Right($r)'),
125125
);
126126
127-
/// Convert to [Maybe]
128-
final maybe = right.toMaybe();
127+
/// Convert to [Option]
128+
final option = right.toOption();
129129
```
130130

131131
### [Reader](https://github.com/SandroMaglione/fpdart/blob/9da7cae3b9f9dc690ff3255004393c4b979183e9/lib/src/reader.dart#L5)
@@ -150,7 +150,7 @@ Many non-functional languages are slowly adopting patterns from functional langu
150150

151151
Many packages are bringing functional patterns to dart, like the amazing [freezed](https://pub.dev/packages/freezed) for unions/pattern matching.
152152

153-
Fpdart aims to provide all the main types found in functional languages to dart. Types like `Maybe` (handle missing values without `null`), `Either` (handle errors and error messages), `Task` (composable async computations), and more.
153+
Fpdart aims to provide all the main types found in functional languages to dart. Types like `Option` (handle missing values without `null`), `Either` (handle errors and error messages), `Task` (composable async computations), and more.
154154

155155
### Goal
156156

@@ -188,14 +188,15 @@ In general, any contribution or feedback is welcome (and encouraged!).
188188

189189
## Versioning
190190

191+
- v0.0.3 - 13 June 2021
191192
- v0.0.2 - 13 June 2021
192193
- v0.0.1 - 28 May 2021
193194

194195
## Support
195196

196197
Currently the best way to support me would be to follow me on my [**Twitter**](https://twitter.com/SandroMaglione).
197198

198-
Another option (or `Maybe`) would be to buy me a coffee.
199+
Another option (or `Option`) would be to buy me a coffee.
199200

200201
<a href="https://www.buymeacoffee.com/sandromaglione">
201202
<img src="https://shields.io/badge/sandromaglione-Support--me-FFDD00?logo=buy-me-a-coffee&style=for-the-badge&link=https://www.buymeacoffee.com/sandromaglione" />

example/main.dart

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ import 'package:fpdart/fpdart.dart';
22

33
void main() {}
44

5-
void maybe() {
6-
/// Create an instance of [Just]
7-
final maybe = Maybe.of(10);
5+
void option() {
6+
/// Create an instance of [Some]
7+
final option = Option.of(10);
88

9-
/// Create an instance of [Nothing]
10-
final nothing = Maybe<int>.nothing();
9+
/// Create an instance of [None]
10+
final none = Option<int>.none();
1111

1212
/// Map [int] to [String]
13-
final map = maybe.map((a) => '$a');
13+
final map = option.map((a) => '$a');
1414

15-
/// Extract the value from [Maybe]
16-
final value = maybe.getOrElse(() => -1);
15+
/// Extract the value from [Option]
16+
final value = option.getOrElse(() => -1);
1717

1818
/// Pattern matching
19-
final match = maybe.match(
20-
(just) => print('Just($just)'),
21-
() => print('Nothing'),
19+
final match = option.match(
20+
(a) => print('Some($a)'),
21+
() => print('None'),
2222
);
2323

2424
/// Convert to [Either]
25-
final either = maybe.toEither(() => 'missing');
25+
final either = option.toEither(() => 'missing');
2626

2727
/// Chain computations
28-
final flatMap = maybe.flatMap((a) => Maybe.of(a + 10));
28+
final flatMap = option.flatMap((a) => Option.of(a + 10));
2929

30-
/// Return [Nothing] if the function throws an error
31-
final tryCatch = Maybe.tryCatch(() => int.parse('invalid'));
30+
/// Return [None] if the function throws an error
31+
final tryCatch = Option.tryCatch(() => int.parse('invalid'));
3232
}
3333

3434
void either() {
@@ -63,6 +63,6 @@ void either() {
6363
(r) => print('Right($r)'),
6464
);
6565

66-
/// Convert to [Maybe]
67-
final maybe = right.toMaybe();
66+
/// Convert to [Option]
67+
final option = right.toOption();
6868
}

example/src/either/overview.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ void main() {
3232
(r) => print('Right($r)'),
3333
);
3434

35-
/// Convert to [Maybe]
36-
final maybe = right.toMaybe();
35+
/// Convert to [Option]
36+
final option = right.toOption();
3737
}

example/src/maybe/overview.dart

-30
This file was deleted.

example/src/maybe/maybe1.dart example/src/option/option1.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void main() {
1919
printString(str);
2020
}
2121

22-
final Maybe<String> mStr = Maybe.of('name');
22+
final Option<String> mStr = Option.of('name');
2323

24-
/// Using [Maybe] you are required to specify every possible case.
24+
/// Using [Option] you are required to specify every possible case.
2525
/// The type system helps you to find and define edge-cases and avoid errors.
2626
mStr.match(
2727
printString,

example/src/maybe/maybe2.dart example/src/option/option2.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import 'package:fpdart/fpdart.dart';
33
double sumToDouble(int a, int b) => (a + b).toDouble();
44

55
void main() {
6-
final a = Maybe.of(10);
7-
final b = Maybe.of(20);
6+
final a = Option.of(10);
7+
final b = Option.of(20);
88

99
/// `map` takes one parameter [int] and returns `sumToDouble`.
10-
/// We therefore have a function inside a [Maybe] that we want to
10+
/// We therefore have a function inside a [Option] that we want to
1111
/// apply to another value!
12-
final Maybe<double Function(int)> map = a.map(
12+
final Option<double Function(int)> map = a.map(
1313
(a) => (int b) => sumToDouble(a, b),
1414
);
1515

16-
/// Using `ap`, we get the final `Maybe<double>` that we want 🚀
16+
/// Using `ap`, we get the final `Option<double>` that we want 🚀
1717
final result = b.ap(map);
1818
}

example/src/maybe/maybe3.dart example/src/option/option3.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ double? intToDoubleNull(int a) {
1616
}
1717
}
1818

19-
Maybe<int> stringToInt(String a) => Maybe.fromPredicateMap<String, int>(
19+
Option<int> stringToInt(String a) => Option.fromPredicateMap<String, int>(
2020
a,
2121
(str) => str.isNotEmpty,
2222
(str) => str.length,
2323
);
2424

25-
Maybe<double> intToDouble(int a) =>
26-
Maybe.fromPredicateMap<int, double>(a, (v) => v != 0, (v) => v / 2);
25+
Option<double> intToDouble(int a) =>
26+
Option.fromPredicateMap<int, double>(a, (v) => v != 0, (v) => v / 2);
2727

2828
void main() {
2929
/// Using `null`, you are required to check that the value is not
@@ -40,10 +40,10 @@ void main() {
4040
/// Using `flatMap`, you can forget that the value may be missing and just
4141
/// use it as if it was there.
4242
///
43-
/// In case one of the values is actually missing, you will get a [Nothing]
43+
/// In case one of the values is actually missing, you will get a [None]
4444
/// at the end of the chain ⛓
45-
final a = Maybe.of('name');
46-
final Maybe<double> result = a.flatMap(
45+
final a = Option.of('name');
46+
final Option<double> result = a.flatMap(
4747
(s) => stringToInt(s).flatMap(
4848
(i) => intToDouble(i),
4949
),

example/src/option/overview.dart

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:fpdart/fpdart.dart';
2+
3+
void main() {
4+
/// Create an instance of [Some]
5+
final option = Option.of(10);
6+
7+
/// Create an instance of [None]
8+
final none = Option<int>.none();
9+
10+
/// Map [int] to [String]
11+
final map = option.map((a) => '$a');
12+
13+
/// Extract the value from [Option]
14+
final value = option.getOrElse(() => -1);
15+
16+
/// Pattern matching
17+
final match = option.match(
18+
(a) => print('Some($a)'),
19+
() => print('None'),
20+
);
21+
22+
/// Convert to [Either]
23+
final either = option.toEither(() => 'missing');
24+
25+
/// Chain computations
26+
final flatMap = option.flatMap((a) => Option.of(a + 10));
27+
28+
/// Return [None] if the function throws an error
29+
final tryCatch = Option.tryCatch(() => int.parse('invalid'));
30+
}

lib/fpdart.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export 'src/either.dart';
22
export 'src/function.dart';
33
export 'src/ilist.dart';
4-
export 'src/maybe.dart';
4+
export 'src/option.dart';
55
export 'src/reader.dart';
66
export 'src/state.dart';
77
export 'src/task.dart';

0 commit comments

Comments
 (0)