Update docs
Some checks failed
Lint / lint (push) Failing after 12s
Publish / publish (push) Failing after 12s

This commit is contained in:
Julien Valverdé
2026-03-25 02:34:42 +01:00
parent 1d3a36a412
commit 49a3488039
2 changed files with 70 additions and 5 deletions

View File

@@ -52,3 +52,35 @@ Effect.gen(function*() {
// Mutations with the parent state are performed immutably by default
// unless you use a specific mutable transform such as 'focusMutableField'
})
Effect.gen(function*() {
interface User {
readonly name: string
readonly age: DateTime.Utc
}
const ref = yield* SubscriptionRef.make<readonly User[]>([
{ name: "Jean Dupont", age: yield* DateTime.make("03/25/1969") },
{ name: "Juan Joya Borja", age: yield* DateTime.make("04/05/1956") },
{ name: "Benzemonstre", age: yield* DateTime.make("06/12/2000") },
])
// \/ Lens<User, NoSuchElementException, NoSuchElementException, never, never>
const benzemonstreLens = ref.pipe(
Lens.fromSubscriptionRef,
// Manually focus
Lens.mapEffect(
// Getter:
Array.get(2),
// Setter:
(a, b) => Array.replaceOption(a, 2, b),
// ^ The current Lens value (readonly User[])
// ^ The new focused value to push (User)
),
)
// Both Array.get and Array.replaceOption return an Option
// When evaluated by the lens, Option<A> becomes Effect<A, NoSuchElementException>
// As you can see, this is automatically tracked by the Lens type
})