Update docs
This commit is contained in:
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user