Running an Effect Inside an Option in TypeScript

how to run an effect inside an option?
is there a way to achieve this?
        yield* Option.gen(function* () {
          const newMappings = yield* insertedRows.pipe(
            Option.map((rows) =>
              rows.map((row) => ({
                name: Record.get(row, "name").pipe(Option.getOrThrow) as string,
                id: Record.get(row, "id").pipe(Option.getOrThrow) as number,
              }))
            ),
            Option.orElse(() =>
              Option.some([] as {
                name: string;
                id: number;
              }[])
            ),
          );
          yield* cacheService.insertIntoCache(newMappings); // an Effect HERE!
          return Record.union(
            Record.fromEntries(
              newMappings.map((mapping) =>
                Tuple.make(mapping.name, mapping.id)
              ),
            ),
            cachedMappings,
            (a, _) => a,
          );
        });
Was this page helpful?