Minor Changes
-
#3380
1e0fe80
Thanks @tim-smart! - make List.Cons extend NonEmptyIterable -
#3380
8135294
Thanks @tim-smart! - add DateTime moduleThe
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
andDateTime.Zoned
.A
DateTime.Utc
represents a time in Coordinated Universal Time (UTC), and
aDateTime.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 apiThis 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
theemit
helper to signal the end of the stream by using apis such as
emit.end
oremit.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 thebufferSize
andstrategy
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.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
2d09078
Thanks @sukovanej! - AddRandom.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! - SupportRefinement
inPredicate.tuple
andPredicate.struct
-
#3380
e74cc38
Thanks @dilame! - ImplementStream.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! - ImplementStream.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! - addbufferSize
option to Stream.fromEventListener -
#3380
7d02174
Thanks @fubhy! - Changed various function signatures to returnArray
instead ofReadonlyArray