Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMaglione committed Mar 25, 2024
1 parent dcb9861 commit 24449a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions examples/fpdart_http/lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ Effect<http.Client, HttpError, http.Response> get(
}) =>

/// 2️⃣ Use the Do notation with the `gen` constructor
Effect.gen((_) async {
Effect.gen(($) async {
/// 3️⃣ Extract the dependency using `env` (environment)
final client = _.sync(Effect.env());
final client = $.sync(Effect.env());

/// 4️⃣ Perform a request, catch errors, extract the response
final response = await _.async(Effect.tryCatch(
final response = await $.async(Effect.tryCatch(
execute: () => client.get(url, headers: headers),
onError: (_, __) => const RequestError(),
));

/// 5️⃣ Use plain dart code to check for valid status
if (response.statusCode != 200) {
return _.sync(Effect.fail(const ResponseError()));
return $.sync(Effect.fail(const ResponseError()));
}

/// 6️⃣ Return extracted/valid response
Expand Down
5 changes: 3 additions & 2 deletions examples/fpdart_http/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void main() async {
() => print(response.body),
),
)
.runFuture(
.provide(
http.Client(),
);
)
.runFuture();
}

0 comments on commit 24449a3

Please sign in to comment.