From fd03044b5d8930a34dc26179c70398715bd22227 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sat, 27 Apr 2024 07:15:09 +0200 Subject: [PATCH 1/2] improve readme. --- README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b9647e3..f7e90a9 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,9 @@ import { Effect } from "effect"; export const getTodoById = (id: string) => Effect.gen(function* () { - const todoService = yield* TodoService; - const todo = yield* todoService.getTodoById("some-id"); + const todo = yield* TodoService.getTodoById("some-id"); if (todo.description.length < 2) { - yield* Effect.fail(new ValidationError("Too small description")); + return yield* Effect.fail(new ValidationError("Too small description")); } return todo; }); @@ -26,10 +25,9 @@ Using `simply-effect`: import { effect } from "simply-effect"; export const getTodoById = effect(function* (id: string) { - const todoService = yield* TodoService; - const todo = yield* todoService.getTodoById("some-id"); + const todo = yield* TodoService.getTodoById("some-id"); if (todo.description.length < 2) { - yield* Effect.fail(new ValidationError("Too small description")); + return yield* Effect.fail(new ValidationError("Too small description")); } return todo; }); @@ -39,7 +37,7 @@ If the generator function has no arguments, then `effect` will work exactly the ```tsx const value: Effect.Effect = effect(function* () { - return yield* Effect.succeed(1); + yield* Console.log(1); }); ``` @@ -49,7 +47,7 @@ It can work together with classes as well, but an extra type annotations for `th class MyService { readonly local = 1; compute = effect(this, function* (this: MyService, add: number) { - return yield* Effect.succeed(this.local + add); + yield* Console.log(this.local + add); }); } ``` From ee405e2ea1ab618af739b1d0e5368ce349283fb2 Mon Sep 17 00:00:00 2001 From: Patrick Roza Date: Sat, 27 Apr 2024 09:29:10 +0200 Subject: [PATCH 2/2] fix type annotation --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7e90a9..2c026c0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ export const getTodoById = (id: string) => Effect.gen(function* () { const todo = yield* TodoService.getTodoById("some-id"); if (todo.description.length < 2) { - return yield* Effect.fail(new ValidationError("Too small description")); + return yield* new ValidationError("Too small description"); } return todo; }); @@ -27,7 +27,7 @@ import { effect } from "simply-effect"; export const getTodoById = effect(function* (id: string) { const todo = yield* TodoService.getTodoById("some-id"); if (todo.description.length < 2) { - return yield* Effect.fail(new ValidationError("Too small description")); + return yield* new ValidationError("Too small description"); } return todo; }); @@ -36,7 +36,7 @@ export const getTodoById = effect(function* (id: string) { If the generator function has no arguments, then `effect` will work exactly the same as `Effect.gen`. ```tsx -const value: Effect.Effect = effect(function* () { +const value: Effect.Effect = effect(function* () { yield* Console.log(1); }); ```