Packages

effect

4.1.4 · 11 Nov 2026MIT66.6M / weekRepositoryHomepagenpmAtom feed

Your version

3.6.0

30 Jul 2024Where it was published

3.22.5 is the newest release of 3.x.

In short

11 new

Security

2 advisories affect 3.6.0; 3.22.1 fixes them

Release note

Minor Changes

  • Make List.Cons extend NonEmptyIterable

  • Add DateTime module

    The DateTime module provides functionality for working with time, including
    support for time zones and daylight saving time.

    It has two main data types: DateTime.Utc and DateTime.Zoned.

    A DateTime.Utc represents a time in Coordinated Universal Time (UTC), and
    a DateTime.Zoned contains both a UTC timestamp and a time zone.

    There is also a CurrentTimeZone service, for setting a time zone contextually.

    import { DateTime, Effect } from "effect";
    
    Effect.gen(function* () {
      // Get the current time in the current time zone
      const now = yield* DateTime.nowInCurrentZone;
    
      // Math functions are included
      const tomorrow = DateTime.add(now, 1, "day");
    
      // Convert to a different time zone
      // The UTC portion of the `DateTime` is preserved and only the time zone is
      // changed
      const sydneyTime = tomorrow.pipe(
        DateTime.unsafeSetZoneNamed("Australia/Sydney"),
      );
    }).pipe(DateTime.withCurrentZoneNamed("America/New_York"));
  • Add Stream.asyncPush api

    This api creates a stream from an external push-based resource.

    You can use the emit helper to emit values to the stream. You can also use
    the emit helper to signal the end of the stream by using apis such as
    emit.end or emit.fail.

    By default it uses an "unbounded" buffer size.
    You can customize the buffer size and strategy by passing an object as the
    second argument with the bufferSize and strategy fields.

    import { Effect, Stream } from "effect";
    
    Stream.asyncPush<string>(
      (emit) =>
        Effect.acquireRelease(
          Effect.gen(function* () {
            yield* Effect.log("subscribing");
            return setInterval(() => emit.single("tick"), 1000);
          }),
          (handle) =>
            Effect.gen(function* () {
              yield* Effect.log("unsubscribing");
              clearInterval(handle);
            }),
        ),
      { bufferSize: 16, strategy: "dropping" },
    );
  • Implement Struct.keys as a typed alternative to Object.keys

    import { Struct } from "effect";
    
    const symbol: unique symbol = Symbol();
    
    const value = {
      a: 1,
      b: 2,
      [symbol]: 3,
    };
    
    const keys: Array<"a" | "b"> = Struct.keys(value);
  • Add Random.choice.

    import { Random } from "effect";
    
    Effect.gen(function* () {
      const randomItem = yield* Random.choice([1, 2, 3]);
      console.log(randomItem);
    });
  • Add onlyEffect option to Effect.tap

  • Support Refinement in Predicate.tuple and Predicate.struct

  • Implement Stream.onEnd that adds an effect to be executed at the end of the stream.

    import { Console, Effect, Stream } from "effect";
    
    const stream = Stream.make(1, 2, 3).pipe(
      Stream.map((n) => n * 2),
      Stream.tap((n) => Console.log(`after mapping: ${n}`)),
      Stream.onEnd(Console.log("Stream ended")),
    );
    
    Effect.runPromise(Stream.runCollect(stream)).then(console.log);
    // after mapping: 2
    // after mapping: 4
    // after mapping: 6
    // Stream ended
    // { _id: 'Chunk', values: [ 2, 4, 6 ] }
  • Implement Stream.onStart that adds an effect to be executed at the start of the stream.

    import { Console, Effect, Stream } from "effect";
    
    const stream = Stream.make(1, 2, 3).pipe(
      Stream.onStart(Console.log("Stream started")),
      Stream.map((n) => n * 2),
      Stream.tap((n) => Console.log(`after mapping: ${n}`)),
    );
    
    Effect.runPromise(Stream.runCollect(stream)).then(console.log);
    // Stream started
    // after mapping: 2
    // after mapping: 4
    // after mapping: 6
    // { _id: 'Chunk', values: [ 2, 4, 6 ] }
  • Add bufferSize option to Stream.fromEventListener

  • Changed various function signatures to return Array instead of ReadonlyArray

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.