0.2.5 #43

Merged
Thilawyn merged 94 commits from next into master 2026-03-31 21:01:13 +02:00
3 changed files with 6 additions and 45 deletions
Showing only changes of commit 285fc84275 - Show all commits

View File

@@ -1,12 +1,15 @@
import { Effect, Pipeable, Predicate, Readable, Stream, Subscribable, type SubscriptionRef } from "effect" import { Effect, Pipeable, Predicate, Readable, Stream, Subscribable, type SubscriptionRef } from "effect"
import * as Writable from "./Writable.js"
export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens") export const LensTypeId: unique symbol = Symbol.for("@effect-fc/Lens/Lens")
export type LensTypeId = typeof LensTypeId export type LensTypeId = typeof LensTypeId
export interface Lens<in out A, ER = never, RR = never, EW = never, RW = never> export interface Lens<in out A, ER = never, RR = never, EW = never, RW = never>
extends LensPrototype, Subscribable.Subscribable<A, ER, RR>, Writable.Writable<A, EW, RW> {} extends Subscribable.Subscribable<A, ER, RR>, LensPrototype {
readonly modify: <B, E1 = never, R1 = never>(
f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>
) => Effect.Effect<B, ER | EW | E1, RR | RW | R1>
}
export interface LensPrototype extends Pipeable.Pipeable { export interface LensPrototype extends Pipeable.Pipeable {
@@ -15,7 +18,6 @@ export interface LensPrototype extends Pipeable.Pipeable {
export const LensPrototype: LensPrototype = Object.freeze({ export const LensPrototype: LensPrototype = Object.freeze({
...Pipeable.Prototype, ...Pipeable.Prototype,
...Writable.WritablePrototype,
[Readable.TypeId]: Readable.TypeId, [Readable.TypeId]: Readable.TypeId,
[Subscribable.TypeId]: Subscribable.TypeId, [Subscribable.TypeId]: Subscribable.TypeId,
[LensTypeId]: LensTypeId, [LensTypeId]: LensTypeId,
@@ -29,8 +31,8 @@ export const make = <A, ER, RR, EW, RW>(
readonly get: Effect.Effect<A, ER, RR> readonly get: Effect.Effect<A, ER, RR>
readonly changes: Stream.Stream<A, ER, RR> readonly changes: Stream.Stream<A, ER, RR>
} & ( } & (
| { readonly modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, EW | E1, RW | R1> }
| { readonly set: (value: A) => Effect.Effect<void, EW, RW> } | { readonly set: (value: A) => Effect.Effect<void, EW, RW> }
| { readonly modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, ER | EW | E1, RR | RW | R1> }
) )
): Lens<A, ER, RR, EW, RW> => Object.setPrototypeOf({ ): Lens<A, ER, RR, EW, RW> => Object.setPrototypeOf({
get: options.get, get: options.get,

View File

@@ -1,40 +0,0 @@
import { Effect, Pipeable, Predicate } from "effect"
export const WritableTypeId: unique symbol = Symbol.for("@effect-fc/Writable/Writable")
export type WritableTypeId = typeof WritableTypeId
export interface Writable<in out A, E = never, R = never> extends WritablePrototype {
readonly modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, E | E1, R | R1>
}
export interface WritablePrototype extends Pipeable.Pipeable {
readonly [WritableTypeId]: WritableTypeId
}
export const WritablePrototype: WritablePrototype = Object.freeze({
[WritableTypeId]: WritableTypeId,
...Pipeable.Prototype,
} as const)
export const isWritable = (u: unknown): u is Writable<unknown, unknown, unknown> => Predicate.hasProperty(u, WritableTypeId)
/**
* Construct a `Writable` from a `modify` function.
*/
export const make = <A, E, R>(
modify: <B, E1 = never, R1 = never>(f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>) => Effect.Effect<B, E | E1, R | R1>,
): Writable<A, E, R> => Object.setPrototypeOf({ modify }, WritablePrototype)
/**
* Unwrap a `Writable` that is wrapped in an `Effect`.
*/
export const unwrap = <A, E, R, E1, R1>(
effect: Effect.Effect<Writable<A, E, R>, E1, R1>
): Writable<A, E | E1, R | R1> => make(
<B, E2 = never, R2 = never>(
f: (a: A) => Effect.Effect<readonly [B, A], E2, R2>
) => Effect.flatMap(effect, w => w.modify(f))
)

View File

@@ -16,4 +16,3 @@ export * as Stream from "./Stream.js"
export * as Subscribable from "./Subscribable.js" export * as Subscribable from "./Subscribable.js"
export * as SubscriptionRef from "./SubscriptionRef.js" export * as SubscriptionRef from "./SubscriptionRef.js"
export * as SubscriptionSubRef from "./SubscriptionSubRef.js" export * as SubscriptionSubRef from "./SubscriptionSubRef.js"
export * as Writable from "./Writable.js"