Exploring Effect Capabilities with Refactored Function

Hey, just started to use Effect in one of my project, I started by refactoring a small function to view the capabilities of Effect:
function findByGithubId(id: string): Effect.Effect<User | undefined, Error> {
  return Effect.tryPromise(
    {
      catch: unknown => new Error(`something went wrong ${unknown}`),
      try: () => db.query.users.findFirst({ where: eq(users.githubId, id) }),
    },
  );
}

const program = Effect.gen(function* (_) {
  const user = yield * _(findByGithubId('23783473'));
  return user;
});

// eslint-disable-next-line no-undef
Effect.runPromise(program).then(console.log);

I have few questions:

This code works, but I was wondering if it is really "effectful" ? Also, can I get rid of the undefined ?
How do I pass the GitHub ID to the gen function ?
If I want to use the "program" in a part of my codebase that isn't using effect yet, can I just do something like const user = await Effect.runPromise(program) ?
Can effect be incrementally adopted ?

Sorry, I haven't finished reading the docs, I just want to play with the library and discovers things for now 😃
Was this page helpful?