Effect CommunityEC
Effect Communityβ€’2y agoβ€’
5 replies
Kasper

Introduction to `simply-effect` Package for Simplifying Effect Handling

Published in a little package simply-effect to allow writing the following:

import { Effect } from "effect";

export const getTodoById = (id: string) =>
  Effect.gen(function* () {
    const todoService = yield* TodoService;
    const todo = yield* todoService.getTodoById("some-id");
    if (todo.description.length < 2) {
      yield* Effect.fail(new ValidationError("Too small description"));
    }
    return todo;
  });


Slightly cleaner in the following way:

import { effect } from "simply-effect";

export const getTodoById = effect(function* (id: string) {
  const todoService = yield* TodoService;
  const todo = yield* todoService.getTodoById("some-id");
  if (todo.description.length < 2) {
    yield* Effect.fail(new ValidationError("Too small description"));
  }
  return todo;
});


https://github.com/kasperpeulen/simply-effect
Was this page helpful?