github Effect-TS/effect effect@2.4.2

Patch Changes

  • #2264 e03811e Thanks @patroza! - fix: unmatched function fallthrough in andThen and tap

  • #2225 ac41d84 Thanks @mikearnaldi! - Add Effect.Tag to simplify access to service.

    This change allows to define tags in the following way:

    class DemoTag extends Effect.Tag("DemoTag")<
      DemoTag,
      {
        readonly getNumbers: () => Array<number>;
        readonly strings: Array<string>;
      }
    >() {}

    And use them like:

    DemoTag.getNumbers();
    DemoTag.strings;

    This fuses together serviceFunctions and serviceConstants in the static side of the tag.

    Additionally it allows using the service like:

    DemoTag.use((_) => _.getNumbers());

    This is especially useful when having functions that contain generics in the service given that those can't be reliably transformed at the type level and because of that we can't put them on the tag.

  • #2238 6137533 Thanks @JJayet! - Request: swap Success and Error params

  • #2270 f373529 Thanks @tim-smart! - add structured logging apis

    • Logger.json / Logger.jsonLogger
    • Logger.structured / Logger.structuredLogger

    Logger.json logs JSON serialized strings to the console.

    Logger.structured logs structured objects, which is useful in the browser
    where you can inspect objects logged to the console.

  • #2257 1bf9f31 Thanks @mikearnaldi! - Make sure Effect.Tag works on primitives.

    This change allows the following to work just fine:

    import { Effect, Layer } from "effect";
    
    class DateTag extends Effect.Tag("DateTag")<DateTag, Date>() {
      static date = new Date(1970, 1, 1);
      static Live = Layer.succeed(this, this.date);
    }
    
    class MapTag extends Effect.Tag("MapTag")<MapTag, Map<string, string>>() {
      static Live = Layer.effect(
        this,
        Effect.sync(() => new Map()),
      );
    }
    
    class NumberTag extends Effect.Tag("NumberTag")<NumberTag, number>() {
      static Live = Layer.succeed(this, 100);
    }
  • #2244 e3ff789 Thanks @tim-smart! - add FiberMap/FiberSet.join api

    This api can be used to propogate failures back to a parent fiber, in case any of the fibers added to the FiberMap/FiberSet fail with an error.

    Example:

    import { Effect, FiberSet } from "effect";
    
    Effect.gen(function* (_) {
      const set = yield* _(FiberSet.make());
      yield* _(FiberSet.add(set, Effect.runFork(Effect.fail("error"))));
    
      // parent fiber will fail with "error"
      yield* _(FiberSet.join(set));
    });
  • #2238 6137533 Thanks @JJayet! - make Effect.request dual

  • #2263 507ba40 Thanks @thewilkybarkid! - Allow duration inputs to be singular

  • #2255 e466afe Thanks @jessekelly881! - added Either.Either.{Left,Right} and Option.Option.Value type utils

  • #2270 f373529 Thanks @tim-smart! - add Logger.batched, for batching logger output

    It takes a duration window and an effectful function that processes the batched output.

    Example:

    import { Console, Effect, Logger } from "effect";
    
    const LoggerLive = Logger.replaceScoped(
      Logger.defaultLogger,
      Logger.logfmtLogger.pipe(
        Logger.batched("500 millis", (messages) =>
          Console.log("BATCH", messages.join("\n")),
        ),
      ),
    );
    
    Effect.gen(function* (_) {
      yield* _(Effect.log("one"));
      yield* _(Effect.log("two"));
      yield* _(Effect.log("three"));
    }).pipe(Effect.provide(LoggerLive), Effect.runFork);
  • #2233 de74eb8 Thanks @gcanti! - Struct: make pick / omit dual

Don't miss a new effect release

NewReleases is sending notifications on new releases.