github Effect-TS/effect effect@3.5.0

latest releases: @effect/sql-sqlite-wasm@0.11.5, @effect/sql-sqlite-react-native@0.14.5, @effect/sql-sqlite-node@0.12.5...
2 months ago

Minor Changes

  • #3048 a1f5b83 Thanks @tim-smart! - add renderErrorCause option to Cause.pretty

  • #3048 60bc3d0 Thanks @tim-smart! - add RcRef module

    An RcRef wraps a reference counted resource that can be acquired and released multiple times.

    The resource is lazily acquired on the first call to get and released when the last reference is released.

    import { Effect, RcRef } from "effect";
    
    Effect.gen(function* () {
      const ref = yield* RcRef.make({
        acquire: Effect.acquireRelease(Effect.succeed("foo"), () =>
          Effect.log("release foo"),
        ),
      });
    
      // will only acquire the resource once, and release it
      // when the scope is closed
      yield* RcRef.get(ref).pipe(Effect.andThen(RcRef.get(ref)), Effect.scoped);
    });
  • #3048 5ab348f Thanks @tim-smart! - allowing customizing Stream pubsub strategy

    import { Schedule, Stream } from "effect";
    
    // toPubSub
    Stream.fromSchedule(Schedule.spaced(1000)).pipe(
      Stream.toPubSub({
        capacity: 16, // or "unbounded"
        strategy: "dropping", // or "sliding" / "suspend"
      }),
    );
    
    // also for the broadcast apis
    Stream.fromSchedule(Schedule.spaced(1000)).pipe(
      Stream.broadcastDynamic({
        capacity: 16,
        strategy: "dropping",
      }),
    );
  • #3048 60bc3d0 Thanks @tim-smart! - add Duration.isZero, for checking if a Duration is zero

  • #3048 3e04bf8 Thanks @sukovanej! - Add Success type util for Config.

  • #3048 e7fc45f Thanks @tim-smart! - add Logger.prettyLogger and Logger.pretty

    Logger.pretty is a new logger that leverages the features of the console APIs to provide a more visually appealing output.

    To try it out, provide it to your program:

    import { Effect, Logger } from "effect";
    
    Effect.log("Hello, World!").pipe(Effect.provide(Logger.pretty));
  • #3048 a1f5b83 Thanks @tim-smart! - add .groupCollapsed to UnsafeConsole

  • #3048 4626de5 Thanks @giacomoran! - export Random.make taking hashable values as seed

  • #3048 f01e7db Thanks @tim-smart! - add replay option to PubSub constructors

    This option adds a replay buffer in front of the given PubSub. The buffer will
    replay the last n messages to any new subscriber.

    Effect.gen(function*() {
      const messages = [1, 2, 3, 4, 5]
      const pubsub = yield* PubSub.bounded<number>({ capacity: 16, replay: 3 })
      yield* PubSub.publishAll(pubsub, messages)
      const sub = yield* PubSub.subscribe(pubsub)
      assert.deepStrictEqual(Chunk.toReadonlyArray(yield* Queue.takeAll(sub)), [3, 4, 5])
    }))
  • #3048 60bc3d0 Thanks @tim-smart! - add RcMap module

    An RcMap can contain multiple reference counted resources that can be indexed
    by a key. The resources are lazily acquired on the first call to get and
    released when the last reference is released.

    Complex keys can extend Equal and Hash to allow lookups by value.

    import { Effect, RcMap } from "effect";
    
    Effect.gen(function* () {
      const map = yield* RcMap.make({
        lookup: (key: string) =>
          Effect.acquireRelease(Effect.succeed(`acquired ${key}`), () =>
            Effect.log(`releasing ${key}`),
          ),
      });
    
      // Get "foo" from the map twice, which will only acquire it once
      // It will then be released once the scope closes.
      yield* RcMap.get(map, "foo").pipe(
        Effect.andThen(RcMap.get(map, "foo")),
        Effect.scoped,
      );
    });
  • #3048 ac71f37 Thanks @dilame! - Ensure Scope is excluded from R in the Channel / Stream run* functions.

    This fix ensures that Scope is now properly excluded from the resulting effect environment.
    The affected functions include run, runCollect, runCount, runDrain and other non-scoped run* in both Stream and Channel modules.
    This fix brings the type declaration in line with the runtime implementation.

  • #3048 8432360 Thanks @dilame! - refactor(Stream/mergeLeft): rename self/that argument names to left/right for clarity

    refactor(Stream/mergeRight): rename self/that argument names to left/right for clarity

  • #3048 e4bf1bf Thanks @dilame! - feat(Stream): implement "raceAll" operator, which returns a stream that mirrors the first source stream to emit an item.

    import { Stream, Schedule, Console, Effect } from "effect";
    
    const stream = Stream.raceAll(
      Stream.fromSchedule(Schedule.spaced("1 millis")),
      Stream.fromSchedule(Schedule.spaced("2 millis")),
      Stream.fromSchedule(Schedule.spaced("4 millis")),
    ).pipe(Stream.take(6), Stream.tap(Console.log));
    
    Effect.runPromise(Stream.runDrain(stream));
    // Output only from the first stream, the rest streams are interrupted
    // 0
    // 1
    // 2
    // 3
    // 4
    // 5
  • #3048 13cb861 Thanks @dilame! - refactor(Stream): use new built-in Types.TupleOf instead of Stream.DynamicTuple and deprecate it

  • #3048 79d2d91 Thanks @tim-smart! - support ErrorOptions in YieldableError constructor

  • #3048 9f66825 Thanks @tim-smart! - allow customizing the output buffer for the Stream.async* apis

    import { Stream } from "effect";
    
    Stream.async<string>(
      (emit) => {
        // ...
      },
      {
        bufferSize: 16,
        strategy: "dropping", // you can also use "sliding" or "suspend"
      },
    );

Patch Changes

Don't miss a new effect release

NewReleases is sending notifications on new releases.