effect@3.6.0
Minor Changes
-
#3380
1e0fe80Thanks @tim-smart! - make List.Cons extend NonEmptyIterable -
#3380
8135294Thanks @tim-smart! - add DateTime moduleThe
DateTimemodule provides functionality for working with time, including
support for time zones and daylight saving time.It has two main data types:
DateTime.UtcandDateTime.Zoned.A
DateTime.Utcrepresents a time in Coordinated Universal Time (UTC), and
aDateTime.Zonedcontains both a UTC timestamp and a time zone.There is also a
CurrentTimeZoneservice, 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
cd255a4Thanks @tim-smart! - add Stream.asyncPush apiThis api creates a stream from an external push-based resource.
You can use the
emithelper to emit values to the stream. You can also use
theemithelper to signal the end of the stream by using apis such as
emit.endoremit.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 thebufferSizeandstrategyfields.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
3845646Thanks @mikearnaldi! - Implement Struct.keys as a typed alternative to Object.keysimport { 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
2d09078Thanks @sukovanej! - AddRandom.choice.import { Random } from "effect"; Effect.gen(function* () { const randomItem = yield* Random.choice([1, 2, 3]); console.log(randomItem); });
-
#3380
4bce5a0Thanks @vinassefranche! - Add onlyEffect option to Effect.tap -
#3380
4ddbff0Thanks @KhraksMamtsov! - SupportRefinementinPredicate.tupleandPredicate.struct -
#3380
e74cc38Thanks @dilame! - ImplementStream.onEndthat 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
bb069b4Thanks @dilame! - ImplementStream.onStartthat 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
cd255a4Thanks @tim-smart! - addbufferSizeoption to Stream.fromEventListener -
#3380
7d02174Thanks @fubhy! - Changed various function signatures to returnArrayinstead ofReadonlyArray