Effect 3.13 has been released! This release includes a number of new features and improvements. Here’s a summary of what’s new:
Schema.standardSchemaV1
This API allows you to generate a Standard Schema v1 object from an Effect Schema.
1
import { Schema } from "effect"
2
3
const schema = Schema.Struct({
4
name: Schema.String
5
})
6
7
// ┌─── StandardSchemaV1<{ readonly name: string; }>
8
// ▼
9
const standardSchema = Schema.standardSchemaV1(schema)
Effect.fn improvements
Effect.fn
has been improved to allow you to access the function arguments inside any of the pipeline functions.
1
import { Effect } from "effect"
2
3
const fn = Effect.fn("my function")(
4
function* (n: number) {
5
yield* Effect.log(`n is ${n}`)
6
},
7
// you can now access the arguments here
8
(effect, n) => Effect.annotateLogs(effect, { n })
9
)
RcMap improvements
-
RcMap.invalidate
has been added, for invalidating a resource at the given key. -
RcMap.touch
has been added, for refreshing the idle timeout of a resource at the given key.
1
import { Effect, RcMap } from "effect"
2
3
Effect.gen(function* () {
4
const map = yield* RcMap.make({
5
lookup: (n: number) => Effect.succeed(n),
6
idleTimeToLive: "1 minute"
7
})
8
9
// retrieve the resource at key 1
10
yield* Effect.scoped(RcMap.get(map, 1))
11
12
// refresh the idle timeout of the resource at key 1
13
yield* RcMap.touch(map, 1)
14
15
// invalidate the resource at key 1
16
yield* RcMap.invalidate(map, 1)
17
})
Effect.transposeOption
This function transforms an Option<Effect<A, E, R>>
into anEffect<Option<A>, E, R>
. If the Option
is None
, the resulting Effect
will immediately succeed with a None
value. If the Option
is Some
, the inner Effect
will be executed, and its result wrapped in a Some
.
1
import { Effect, Option } from "effect"
2
3
// ┌─── Option<Effect<number, never, never>>
4
// ▼
5
const maybe = Option.some(Effect.succeed(42))
6
7
// ┌─── Effect<Option<number>, never, never>
8
// ▼
9
const result = Effect.transposeOption(maybe)
10
11
console.log(Effect.runSync(result))
12
// Output: { _id: 'Option', _tag: 'Some', value: 42 }