0.2.0 #5

Merged
Thilawyn merged 59 commits from next into master 2026-05-30 06:10:54 +02:00
Showing only changes of commit 253d19be3a - Show all commits
+46
View File
@@ -0,0 +1,46 @@
import { Console, Effect, Stream, SubscriptionRef } from "effect"
import { Lens } from "./index.js"
class State extends Effect.Service<State>()("State", {
effect: Effect.gen(function*() {
const ref = yield* SubscriptionRef.make({
users: [
{ name: "Adolf" }
]
})
return {
lens: Lens.fromSubscriptionRef(ref)
} as const
})
}) {}
Effect.gen(function*() {
const lens = Lens.unwrap(Effect.andThen(
State,
state => state.lens,
)).pipe(
Lens.provideContext(yield* Effect.provide(Effect.context<State>(), State.Default))
)
const adolfNameLens = lens.pipe(
Lens.focusObjectOn("users"),
Lens.focusArrayAt(0),
Lens.focusObjectOn("name"),
Lens.catchAllRead(() => Lens.makeLazy({
sourceGet: Effect.succeed("User not found"),
sourceChanges: Stream.make("User not found"),
sourceCommit: () => Console.log("Test"),
withLock: Effect.unsafeMakeSemaphore(1).withPermits(1),
})),
)
console.log(yield* Lens.get(adolfNameLens))
yield* Lens.set(lens, { users: [] })
yield* Lens.set(adolfNameLens, "Himmler")
console.log(yield* Lens.get(adolfNameLens))
}).pipe(
Effect.runSync,
)