Skip to content

Commit

Permalink
Fix: Bind Extensions (#11)
Browse files Browse the repository at this point in the history
* Initial commit
* Bump version number and update changelog
  • Loading branch information
callius authored Dec 5, 2023
1 parent e3caaaa commit a30325e
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 17 deletions.
7 changes: 7 additions & 0 deletions packages/target/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.1

Fixes:

- Typing for `Either.bindTo`.
- Typing for `Future<Either>.thenBind`.

## 0.6.0

Features:
Expand Down
3 changes: 2 additions & 1 deletion packages/target/lib/src/raise.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ A merge<A>(A Function(Raise<A>) block) => recover(block, id);
Future<A> mergeAsync<A>(Future<A> Function(Raise<A>) block) =>
recoverAsync(block, id);

extension RaiseEitherExtension<Error, A> on Either<Error, A> {
extension RaiseEitherExtension<Error, Error2 extends Error, A>
on Either<Error2, A> {
/// Binds this to the given [Raise].
///
/// Note: [bind] member function already exists on [Either].
Expand Down
2 changes: 1 addition & 1 deletion packages/target/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: target
description: Functional domain modeling in Dart.
version: 0.6.0
version: 0.6.1
repository: https://github.com/callius/target-dart/tree/main/packages/target
issue_tracker: https://github.com/callius/target-dart/issues
homepage: https://github.com/callius/target-dart
Expand Down
8 changes: 4 additions & 4 deletions packages/target/test/raise_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:dartz/dartz.dart';
import 'package:target/src/raise.dart';
import 'package:target/src/raise_builders.dart';
import 'package:target/target.dart';
import 'package:test/test.dart';

void main() {
Expand Down Expand Up @@ -177,9 +176,10 @@ void main() {

group('Either.bindTo', () {
test('returns left when left', () async {
const testLeft = Left<String, Unit>('failure');
const testLeft =
Left<GenericValueFailure<Unit>, Unit>(GenericValueFailure(unit));

final result = either<String, Unit>((r) {
final result = either<ValueFailure<Unit>, Unit>((r) {
testLeft.bindTo(r);
return unit;
});
Expand Down
7 changes: 7 additions & 0 deletions packages/target_annotation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.1

Fixes:

- Typing for `Either.bindTo`.
- Typing for `Future<Either>.thenBind`.

## 0.6.0

Features:
Expand Down
2 changes: 1 addition & 1 deletion packages/target_annotation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: target_annotation
description: Functional domain modeling in Dart.
version: 0.6.0
version: 0.6.1
repository: https://github.com/callius/target-dart/tree/main/packages/target_annotation
issue_tracker: https://github.com/callius/target-dart/issues
homepage: https://github.com/callius/target-dart
Expand Down
7 changes: 7 additions & 0 deletions packages/target_annotation_processor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.1

Fixes:

- Typing for `Either.bindTo`.
- Typing for `Future<Either>.thenBind`.

## 0.6.0

Features:
Expand Down
8 changes: 4 additions & 4 deletions packages/target_annotation_processor/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: target_annotation_processor
description: Functional domain modeling in Dart.
version: 0.6.0
version: 0.6.1
repository: https://github.com/callius/target-dart/tree/main/packages/target_annotation_processor
issue_tracker: https://github.com/callius/target-dart/issues
homepage: https://github.com/callius/target-dart
Expand All @@ -21,17 +21,17 @@ dependencies:
git:
url: https://github.com/callius/target-dart
path: packages/target
ref: v0.6.0
ref: v0.6.1
target_annotation:
git:
url: https://github.com/callius/target-dart
path: packages/target_annotation
ref: v0.6.0
ref: v0.6.1
target_extension:
git:
url: https://github.com/callius/target-dart
path: packages/target_extension
ref: v0.6.0
ref: v0.6.1

dev_dependencies:
build_runner: null
Expand Down
7 changes: 7 additions & 0 deletions packages/target_extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.1

Fixes:

- Typing for `Either.bindTo`.
- Typing for `Future<Either>.thenBind`.

## 0.6.0

Features:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ extension TargetFutureEitherX<L, R> on Future<Either<L, R>> {
Future<Either<L2, R>> thenLeftMap<L2>(L2 Function(L l) f) {
return then((it) => it.leftMap(f));
}
}

Future<R> thenBind(Raise<L> r) {
extension TargetFutureEitherBindX<Error, L extends Error, R>
on Future<Either<L, R>> {
Future<R> thenBind(Raise<Error> r) {
return then(r.bind);
}
}
4 changes: 2 additions & 2 deletions packages/target_extension/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: target_extension
description: Extensions for functional domain modeling in Dart.
version: 0.6.0
version: 0.6.1
repository: https://github.com/callius/target-dart/tree/main/packages/target_extension
issue_tracker: https://github.com/callius/target-dart/issues
homepage: https://github.com/callius/target-dart
Expand All @@ -15,7 +15,7 @@ dependencies:
git:
url: https://github.com/callius/target-dart
path: packages/target
ref: v0.6.0
ref: v0.6.1

dev_dependencies:
lint: ^2.2.0
Expand Down
8 changes: 5 additions & 3 deletions packages/target_extension/test/either_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:test/scaffolding.dart';
void main() {
group('Future<Either>.thenBind', () {
test('returns left when left', () async {
const testLeft = Left<String, Unit>('f');
const testLeft =
Left<GenericValueFailure<Unit>, Unit>(GenericValueFailure(unit));

final result = await eitherAsync<String, Unit>(
(r) => Future<Either<String, Unit>>.value(testLeft).thenBind(r),
final result = await eitherAsync<ValueFailure<Unit>, Unit>(
(r) => Future<Either<GenericValueFailure<Unit>, Unit>>.value(testLeft)
.thenBind(r),
);

expect(result, testLeft);
Expand Down

0 comments on commit a30325e

Please sign in to comment.