Skip to content

Effect 3.1 (Release)

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

This new api allows you to create a Stream from an EventTarget:

1
import { Stream } from "effect/Stream"
2
3
Stream.fromEventListener(window, "click")

@effect/platform-browser/BrowserStream has also been added, with fromEventListenerWindow & fromEventListenerDocument apis.

A new timeout api has been added, which returns the result of the wrapped Effect as an Option.

If the wrapped Effect times out, a Option.None is returned - otherwise the result is wrapped with Option.Some.

Tracing spans now include a kind field, which is used to indicate the type of system that generated the span.

For example, @effect/platform/HttpServer will generate spans with a kind of server. While @effect/platform/HttpClient will generate spans with a kind of client.

  • Http.multipart.filesSchema has been renamed to Http.multipart.FilesSchema
  • Http.multipart.FileSchema is now exported
  • Http.multipart.SingleFileSchema has been added

A new api has been added to Effect which allows you to annotate logs during the lifetime of a Scope.

1
import { Effect } from "effect"
2
3
Effect.gen(function* () {
4
yield* Effect.log("no annotations")
5
yield* Effect.annotateLogsScoped({ foo: "bar" })
6
yield* Effect.log("annotated with foo=bar")
7
}).pipe(Effect.scoped, Effect.andThen(Effect.log("no annotations again")))

$is & $match helpers have been added to Data.TaggedEnum constructors.

1
import { Data } from "effect"
2
3
type HttpError = Data.TaggedEnum<{
4
NotFound: {}
5
InternalServerError: { reason: string }
6
}>
7
const { $is, $match, InternalServerError, NotFound } =
8
Data.taggedEnum<HttpError>()
9
10
// create a matcher
11
const matcher = $match({
12
NotFound: () => 0,
13
InternalServerError: () => 1
14
})
15
16
// use the guard
17
$is("NotFound")(NotFound()) // true
18
$is("NotFound")(InternalServerError({ reason: "fail" })) // false

A type helper has been added, which transforms a type into a deeply mutable version.

1
import { Types } from "effect"
2
3
type Values<A> = {
4
readonly _tag: string
5
readonly value: ReadonlyArray<A>
6
}
7
8
// { _tag: string, value: Array<A> }
9
type MutableValues<A> = Types.DeepMutable<Values<A>>
  • SortedMap.lastOption has been added
  • SortedMap.partition has been added

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!