Skip to content

Effect 3.2 (Release)

Effect 3.2.0 has been released! This release includes a number of new features and improvements. Here’s a summary of what’s new:

These functions allow you to calculate the difference between two Chunk’s. This can be useful when you want to know what elements are in one chunk but not in another.

1
expect(
2
Chunk.difference(Chunk.make(1, 2, 3, 4, 5), Chunk.make(1, 2, 3))
3
).toEqual(Chunk.make(4, 5))

Tracing spans now capture their source location. This can be useful when debugging and trying to understand where a span was created. It will also add the source location to any errors created within the span.

To disable this feature, pass captureStackTrace: false to the Effect.withSpan options:

1
Effect.log("Hello World").pipe(
2
Effect.withSpan("my span", { captureStackTrace: false }),
3
)

You can use this to extract Error instances from a Cause, that have clean stack traces and have had span information added to them.

This can be useful when integrating Effect with other libraries that expect Error instances.

This api allows you to define an effectful function that is wrapped with a span.

You can also use the function arguments to generate the span options.

1
import { Effect } from "effect";
2
3
const getTodo = Effect.functionWithSpan({
4
body: (id: number) => Effect.succeed(`Got todo ${id}!`),
5
options: (id) => ({
6
name: `getTodo-${id}`,
7
attributes: { id },
8
}),
9
});

Do notation has been added to the Array module, for building up arrays in a sequential manner.

1
const props = pipe(
2
Array.Do,
3
Array.bind("size", () => ["small", "medium", "large"] as const),
4
Array.bind("theme", () => ["dark", "light", "contrast-light", "contrast-dark"] as const),
5
Array.bind("disabled", () => [false, true]),
6
Array.bind("loading", () => [false, true]),
7
)

To convert a Stream to a ReadableStream, that supports using Effect context / requirements, you can use the Stream.toReadableStreamEffect or Stream.toReadableStreamRuntime function.

The $is and $match helpers have been added to the Data.TaggedEnum.WithGenerics constructors. You can use these apis to perform type-safe checks and pattern matching.

1
type Result<E, A> = Data.TaggedEnum<{
2
Success: { value: A }
3
Failure: {
4
error: E
5
message?: string
6
}
7
}>
8
interface ResultDefinition extends Data.TaggedEnum.WithGenerics<2> {
9
readonly taggedEnum: Result<this["A"], this["B"]>
10
}
11
const { $is, $match, Failure, Success } = Data.taggedEnum<ResultDefinition>()
12
13
const result: Result<string, number> = Success({ value: 1 })
14
15
pipe(
16
result,
17
$match({
18
Success: (_) => _.value,
19
Failure: (_) => _.error
20
})
21
) satisfies string | number

There were several other smaller changes made. Take a look through the CHANGELOG to see them all: CHANGELOG.

Don’t forget to join our Discord Community to follow the last updates and discuss every tiny detail!