/** * @tsplus type effect/core/testing/Sized */ export interface Sized { readonly size: Effect readonly withSize: (size: number) => (effect: Effect) => Effect readonly withSizeGen: (size: number) => (gen: Gen) => Gen } /** * @tsplus type effect/core/testing/Sized.Ops */ export interface SizedOps { readonly Tag: Tag } export const Sized: SizedOps = { Tag: Tag() } /** * @tsplus type effect/core/testing/Sized.Aspects */ export interface SizedAspects {} /** * @tsplus static effect/core/testing/Sized.Ops live */ export function live(size: number): Layer { return Layer.scoped( Sized.Tag, FiberRef.make(size).map((fiberRef): Sized => ({ size: fiberRef.get, withSize: (size) => fiberRef.locally(size), withSizeGen: (size) => (gen) => Gen( Stream.fromEffect(fiberRef.get).flatMap((oldSize) => Stream.scoped(fiberRef.locallyScoped(size)) .crossRight(gen.sample.mapEffect((a) => fiberRef.set(oldSize).as(a))) ) ) })) ) } /** * @tsplus static effect/core/testing/Sized.Ops default */ export const defaultSized: Layer = Sized.live(100) /** * @tsplus static effect/core/testing/Sized.Ops size */ export const size: Effect = Effect.serviceWithEffect( Sized.Tag, (sized) => sized.size ) /** * @tsplus static effect/core/testing/Sized.Ops withSize */ export function withSize(size: number) { return (effect: Effect): Effect => Effect.serviceWithEffect( Sized.Tag, (sized) => sized.withSize(size)(effect) ) } /** * @tsplus static effect/core/testing/Sized.Ops withSizeGen */ export function withSizeGen(size: number) { return (gen: Gen): Gen => Gen.fromEffect(Effect.service(Sized.Tag)).flatMap((sized) => sized.withSizeGen(size)(gen)) }