github Effect-TS/effect effect@3.6.0

latest releases: @effect/sql-sqlite-wasm@0.20.4, @effect/typeclass@0.29.13, @effect/vitest@0.13.13...
3 months ago

Minor Changes

  • #3380 1e0fe80 Thanks @tim-smart! - make List.Cons extend NonEmptyIterable

  • #3380 8135294 Thanks @tim-smart! - 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"));
  • #3380 cd255a4 Thanks @tim-smart! - 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" },
    );
  • #3380 3845646 Thanks @mikearnaldi! - 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);
  • #3380 2d09078 Thanks @sukovanej! - Add Random.choice.

    import { Random } from "effect";
    
    Effect.gen(function* () {
      const randomItem = yield* Random.choice([1, 2, 3]);
      console.log(randomItem);
    });
  • #3380 4bce5a0 Thanks @vinassefranche! - Add onlyEffect option to Effect.tap

  • #3380 4ddbff0 Thanks @KhraksMamtsov! - Support Refinement in Predicate.tuple and Predicate.struct

  • #3380 e74cc38 Thanks @dilame! - 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 ] }
  • #3380 bb069b4 Thanks @dilame! - 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 ] }
  • #3380 cd255a4 Thanks @tim-smart! - add bufferSize option to Stream.fromEventListener

  • #3380 7d02174 Thanks @fubhy! - Changed various function signatures to return Array instead of ReadonlyArray

Don't miss a new effect release

NewReleases is sending notifications on new releases.