Created
November 15, 2022 21:50
-
-
Save tim-smart/083a8212d42743ed73f890a0c50d6a1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const make = Effect.struct({ | |
ref: SubscriptionRef.make(0), | |
}); | |
export interface Counter extends Effect.Success<typeof make> {} | |
export const Counter = Tag<Counter>(); | |
export const CounterLive = Layer.fromEffect(Counter)(make); | |
export const increment = Effect.serviceWithEffect(Counter, ({ ref }) => | |
ref.update((count) => count + 1) | |
); | |
export const decrement = Effect.serviceWithEffect(Counter, ({ ref }) => | |
ref.update((count) => count - 1) | |
); | |
export const subscribe = pipe( | |
Effect.serviceWith(Counter, ({ ref }) => ref.changes), | |
Stream.unwrap | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment