Skip to main content Link Search Menu Expand Document (external link)

Rx overview

Added in v1.0.0


Table of contents


batching

batch

Signature

export declare const batch: (f: () => void) => void

Added in v1.0.0

combinators

debounce

Signature

export declare const debounce: {
  (duration: Duration.DurationInput): <A extends Rx<any>>(self: A) => A
  <A extends Rx<any>>(self: A, duration: Duration.DurationInput): A
}

Added in v1.0.0

initialValue

Signature

export declare const initialValue: {
  <A>(initialValue: A): (self: Rx<A>) => readonly [Rx<A>, A]
  <A>(self: Rx<A>, initialValue: A): readonly [Rx<A>, A]
}

Added in v1.0.0

keepAlive

Signature

export declare const keepAlive: <A extends Rx<any>>(self: A) => A

Added in v1.0.0

map

Signature

export declare const map: {
  <R extends Rx<any>, B>(
    f: (_: Rx.Infer<R>) => B
  ): (self: R) => [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Rx<B>
  <R extends Rx<any>, B>(
    self: R,
    f: (_: Rx.Infer<R>) => B
  ): [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Rx<B>
}

Added in v1.0.0

mapResult

Signature

export declare const mapResult: {
  <R extends Rx<Result.Result<any, any>>, B>(
    f: (_: Result.Result.InferA<Rx.Infer<R>>) => B
  ): (
    self: R
  ) => [R] extends [Writable<infer _, infer RW>]
    ? Writable<Result.Result<B, Result.Result.InferE<Rx.Infer<R>>>, RW>
    : Rx<Result.Result<B, Result.Result.InferE<Rx.Infer<R>>>>
  <R extends Rx<Result.Result<any, any>>, B>(
    self: R,
    f: (_: Result.Result.InferA<Rx.Infer<R>>) => B
  ): [R] extends [Writable<infer _, infer RW>]
    ? Writable<Result.Result<B, Result.Result.InferE<Rx.Infer<R>>>, RW>
    : Rx<Result.Result<B, Result.Result.InferE<Rx.Infer<R>>>>
}

Added in v1.0.0

refreshable

Signature

export declare const refreshable: <T extends Rx<any>>(self: T) => T & Refreshable

Added in v1.0.0

setIdleTTL

Signature

export declare const setIdleTTL: {
  (duration: Duration.DurationInput): <A extends Rx<any>>(self: A) => A
  <A extends Rx<any>>(self: A, duration: Duration.DurationInput): A
}

Added in v1.0.0

transform

Signature

export declare const transform: {
  <R extends Rx<any>, B>(
    f: (get: Context) => B
  ): (self: R) => [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Rx<B>
  <R extends Rx<any>, B>(
    self: R,
    f: (get: Context) => B
  ): [R] extends [Writable<infer _, infer RW>] ? Writable<B, RW> : Rx<B>
}

Added in v1.0.0

withFallback

Signature

export declare const withFallback: {
  <E2, A2>(
    fallback: Rx<Result.Result<A2, E2>>
  ): <R extends Rx<Result.Result<any, any>>>(
    self: R
  ) => [R] extends [Writable<infer _, infer RW>]
    ? Writable<Result.Result<A2 | Result.Result.InferA<Rx.Infer<R>>, E2 | Result.Result.InferE<Rx.Infer<R>>>, RW>
    : Rx<Result.Result<A2 | Result.Result.InferA<Rx.Infer<R>>, E2 | Result.Result.InferE<Rx.Infer<R>>>>
  <R extends Rx<Result.Result<any, any>>, A2, E2>(
    self: R,
    fallback: Rx<Result.Result<A2, E2>>
  ): [R] extends [Writable<infer _, infer RW>]
    ? Writable<Result.Result<A2 | Result.Result.InferA<Rx.Infer<R>>, E2 | Result.Result.InferE<Rx.Infer<R>>>, RW>
    : Rx<Result.Result<A2 | Result.Result.InferA<Rx.Infer<R>>, E2 | Result.Result.InferE<Rx.Infer<R>>>>
}

Added in v1.0.0

withLabel

Signature

export declare const withLabel: {
  (name: string): <A extends Rx<any>>(self: A) => A
  <A extends Rx<any>>(self: A, name: string): A
}

Added in v1.0.0

constructors

context

Signature

export declare const context: () => <R, E>(
  create: Layer.Layer<R, E, never> | Rx.Read<Layer.Layer<R, E, never>>
) => RxRuntime<R, E>

Added in v1.0.0

family

Signature

export declare const family: <Arg, T extends object>(f: (arg: Arg) => T) => (arg: Arg) => T

Added in v1.0.0

fn

Signature

export declare const fn: {
  <Arg, E, A>(
    fn: Rx.ReadFn<Arg, Effect.Effect<A, E, Scope.Scope>>,
    options?: { readonly initialValue?: A | undefined } | undefined
  ): RxResultFn<RxResultFn.ArgToVoid<Arg>, A, E>
  <Arg, E, A>(
    fn: Rx.ReadFn<Arg, Stream.Stream<A, E, never>>,
    options?: { readonly initialValue?: A | undefined } | undefined
  ): RxResultFn<RxResultFn.ArgToVoid<Arg>, A, NoSuchElementException | E>
}

Added in v1.0.0

fnSync

Signature

export declare const fnSync: {
  <Arg, A>(f: Rx.ReadFn<Arg, A>): Writable<Option.Option<A>, RxResultFn.ArgToVoid<Arg>>
  <Arg, A>(f: Rx.ReadFn<Arg, A>, options: { readonly initialValue: A }): Writable<A, RxResultFn.ArgToVoid<Arg>>
}

Added in v1.0.0

make

Signature

export declare const make: {
  <A, E>(
    effect: Effect.Effect<A, E, Scope.Scope>,
    options?: { readonly initialValue?: A | undefined } | undefined
  ): Rx<Result.Result<A, E>>
  <A, E>(
    create: Rx.Read<Effect.Effect<A, E, Scope.Scope>>,
    options?: { readonly initialValue?: A | undefined } | undefined
  ): Rx<Result.Result<A, E>>
  <A, E>(
    stream: Stream.Stream<A, E, never>,
    options?: { readonly initialValue?: A | undefined } | undefined
  ): Rx<Result.Result<A, E>>
  <A, E>(
    create: Rx.Read<Stream.Stream<A, E, never>>,
    options?: { readonly initialValue?: A | undefined } | undefined
  ): Rx<Result.Result<A, E>>
  <A>(create: Rx.Read<A>): Rx<A>
  <A>(initialValue: A): Writable<A, A>
}

Added in v1.0.0

pull

Signature

export declare const pull: <A, E>(
  create: Stream.Stream<A, E, never> | Rx.Read<Stream.Stream<A, E, never>>,
  options?:
    | { readonly disableAccumulation?: boolean | undefined; readonly initialValue?: readonly A[] | undefined }
    | undefined
) => Writable<PullResult<A, E>, void>

Added in v1.0.0

readable

Signature

export declare const readable: <A>(read: Rx.Read<A>, refresh?: Rx.Refresh) => Rx<A>

Added in v1.0.0

subscribable

Signature

export declare const subscribable: {
  <A, E>(ref: Subscribable.Subscribable<A, E, never> | Rx.Read<Subscribable.Subscribable<A, E, never>>): Rx<A>
  <A, E, E1>(
    effect:
      | Effect.Effect<Subscribable.Subscribable<A, E1, never>, E, never>
      | Rx.Read<Effect.Effect<Subscribable.Subscribable<A, E1, never>, E, never>>
  ): Rx<A>
}

Added in v1.0.0

subscriptionRef

Signature

export declare const subscriptionRef: {
  <A>(ref: SubscriptionRef.SubscriptionRef<A> | Rx.Read<SubscriptionRef.SubscriptionRef<A>>): Writable<A, A>
  <A, E>(
    effect:
      | Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, never>
      | Rx.Read<Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, never>>
  ): Writable<Result.Result<A, E>, A>
}

Added in v1.0.0

writable

Signature

export declare const writable: <R, W>(read: Rx.Read<R>, write: Rx.Write<R, W>, refresh?: Rx.Refresh) => Writable<R, W>

Added in v1.0.0

context

Context (interface)

Signature

export interface Context {
  <A>(rx: Rx<A>): A
  readonly get: <A>(rx: Rx<A>) => A
  readonly result: <A, E>(rx: Rx<Result.Result<A, E>>) => Effect.Effect<A, E>
  readonly once: <A>(rx: Rx<A>) => A
  readonly addFinalizer: (f: () => void) => void
  readonly mount: <A>(rx: Rx<A>) => void
  readonly refreshSync: <A>(rx: Rx<A> & Refreshable) => void
  readonly refresh: <A>(rx: Rx<A> & Refreshable) => Effect.Effect<void>
  readonly refreshSelfSync: () => void
  readonly refreshSelf: Effect.Effect<void>
  readonly self: <A>() => Option.Option<A>
  readonly setSelfSync: <A>(a: A) => void
  readonly setSelf: <A>(a: A) => Effect.Effect<void>
  readonly setSync: <R, W>(rx: Writable<R, W>, value: W) => void
  readonly set: <R, W>(rx: Writable<R, W>, value: W) => Effect.Effect<void>
  readonly some: <A>(rx: Rx<Option.Option<A>>) => Effect.Effect<A>
  readonly stream: <A>(
    rx: Rx<A>,
    options?: {
      readonly withoutInitialValue?: boolean
      readonly bufferSize?: number
    }
  ) => Stream.Stream<A>
  readonly streamResult: <A, E>(
    rx: Rx<Result.Result<A, E>>,
    options?: {
      readonly withoutInitialValue?: boolean
      readonly bufferSize?: number
    }
  ) => Stream.Stream<A, E>
  readonly subscribe: <A>(
    rx: Rx<A>,
    f: (_: A) => void,
    options?: {
      readonly immediate?: boolean
    }
  ) => void
}

Added in v1.0.0

WriteContext (interface)

Signature

export interface WriteContext<A> {
  readonly get: <A>(rx: Rx<A>) => A
  readonly refreshSelf: () => void
  readonly setSelf: (a: A) => void
  readonly set: <R, W>(rx: Writable<R, W>, value: W) => void
}

Added in v1.0.0

runtime

Signature

export declare const runtime: <R, E>(
  create: Layer.Layer<R, E, never> | Rx.Read<Layer.Layer<R, E, never>>
) => RxRuntime<R, E>

Added in v1.0.0

models

PullResult (type alias)

Signature

export type PullResult<A, E = never> = Result.Result<
  {
    readonly done: boolean
    readonly items: Array<A>
  },
  E | NoSuchElementException
>

Added in v1.0.0

Refreshable (interface)

Signature

export interface Refreshable {
  readonly [RefreshableTypeId]: RefreshableTypeId
}

Added in v1.0.0

Rx (interface)

Signature

export interface Rx<A> extends Pipeable, Inspectable.Inspectable {
  readonly [TypeId]: TypeId
  readonly keepAlive: boolean
  readonly read: Rx.Read<A>
  readonly refresh?: Rx.Refresh
  readonly label?: readonly [name: string, stack: string]
  readonly idleTTL?: number
}

Added in v1.0.0

Rx (namespace)

Added in v1.0.0

Get (type alias)

Signature

export type Get = <A>(rx: Rx<A>) => A

Added in v1.0.0

GetResult (type alias)

Signature

export type GetResult = <A, E>(rx: Rx<Result.Result<A, E>>) => Effect.Effect<A, E>

Added in v1.0.0

Infer (type alias)

Signature

export type Infer<T extends Rx<any>> = T extends Rx<infer A> ? A : never

Added in v1.0.0

InferFailure (type alias)

Signature

export type InferFailure<T extends Rx<any>> = T extends Rx<Result.Result<infer _, infer E>> ? E : never

Added in v1.0.0

InferPullSuccess (type alias)

Signature

export type InferPullSuccess<T extends Rx<any>> = T extends Rx<PullResult<infer A, infer _>> ? A : never

Added in v1.0.0

InferSuccess (type alias)

Signature

export type InferSuccess<T extends Rx<any>> = T extends Rx<Result.Result<infer A, infer _>> ? A : never

Added in v1.0.0

Mount (type alias)

Signature

export type Mount = <A>(rx: Rx<A>) => () => void

Added in v1.0.0

Read (type alias)

Signature

export type Read<A> = (ctx: Context) => A

Added in v1.0.0

ReadFn (type alias)

Signature

export type ReadFn<Arg, A> = (arg: Arg, ctx: Context) => A

Added in v1.0.0

Refresh (type alias)

Signature

export type Refresh = (f: <A>(rx: Rx<A>) => void) => void

Added in v1.0.0

RefreshRx (type alias)

Signature

export type RefreshRx = <A>(rx: Rx<A> & Refreshable) => Effect.Effect<void>

Added in v1.0.0

RefreshRxSync (type alias)

Signature

export type RefreshRxSync = <A>(rx: Rx<A> & Refreshable) => void

Added in v1.0.0

Set (type alias)

Signature

export type Set = <R, W>(rx: Writable<R, W>, value: W) => void

Added in v1.0.0

SetEffect (type alias)

Signature

export type SetEffect = <R, W>(rx: Writable<R, W>, value: W) => Effect.Effect<void>

Added in v1.0.0

Subscribe (type alias)

Signature

export type Subscribe = <A>(
  rx: Rx<A>,
  f: (_: A) => void,
  options?: {
    readonly immediate?: boolean
  }
) => () => void

Added in v1.0.0

Write (type alias)

Signature

export type Write<R, W> = (ctx: WriteContext<R>, value: W) => void

Added in v1.0.0

RxResultFn (interface)

Signature

export interface RxResultFn<Arg, A, E = never> extends Writable<Result.Result<A, E>, Arg | Reset> {}

Added in v1.0.0

RxRuntime (interface)

Signature

export interface RxRuntime<R, ER> extends Rx<Result.Result<Runtime.Runtime<R>, ER>> {
  readonly layer: Rx<Layer.Layer<R, ER>>

  readonly rx: {
    <A, E>(
      effect: Effect.Effect<A, E, Scope.Scope | R>,
      options?: {
        readonly initialValue?: A
      }
    ): Rx<Result.Result<A, E | ER>>
    <A, E>(
      create: Rx.Read<Effect.Effect<A, E, Scope.Scope | R>>,
      options?: {
        readonly initialValue?: A
      }
    ): Rx<Result.Result<A, E | ER>>
    <A, E>(
      stream: Stream.Stream<A, E, never | R>,
      options?: {
        readonly initialValue?: A
      }
    ): Rx<Result.Result<A, E | ER>>
    <A, E>(
      create: Rx.Read<Stream.Stream<A, E, never | R>>,
      options?: {
        readonly initialValue?: A
      }
    ): Rx<Result.Result<A, E | ER>>
  }

  readonly fn: {
    <Arg, E, A>(
      fn: Rx.ReadFn<Arg, Effect.Effect<A, E, Scope.Scope | R>>,
      options?: {
        readonly initialValue?: A
      }
    ): RxResultFn<RxResultFn.ArgToVoid<Arg>, A, E | ER>
    <Arg, E, A>(
      fn: Rx.ReadFn<Arg, Stream.Stream<A, E, R>>,
      options?: {
        readonly initialValue?: A
      }
    ): RxResultFn<RxResultFn.ArgToVoid<Arg>, A, E | ER | NoSuchElementException>
  }

  readonly pull: <A, E>(
    create: Rx.Read<Stream.Stream<A, E, R>> | Stream.Stream<A, E, R>,
    options?: {
      readonly disableAccumulation?: boolean
      readonly initialValue?: ReadonlyArray<A>
    }
  ) => Writable<PullResult<A, E | ER>, void>

  readonly subscriptionRef: <A, E>(
    create:
      | Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, R>
      | Rx.Read<Effect.Effect<SubscriptionRef.SubscriptionRef<A>, E, R>>
  ) => Writable<Result.Result<A, E>, A>

  readonly subscribable: <A, E, E1 = never>(
    create:
      | Effect.Effect<Subscribable.Subscribable<A, E, R>, E1, R>
      | Rx.Read<Effect.Effect<Subscribable.Subscribable<A, E, R>, E1, R>>
  ) => Rx<Result.Result<A, E | E1>>
}

Added in v1.0.0

Writable (interface)

Signature

export interface Writable<R, W> extends Rx<R> {
  readonly [WritableTypeId]: WritableTypeId
  readonly write: Rx.Write<R, W>
}

Added in v1.0.0

refinements

isWritable

Signature

export declare const isWritable: <R, W>(rx: Rx<R>) => rx is Writable<R, W>

Added in v1.0.0

symbols

Reset

Signature

export declare const Reset: typeof Reset

Added in v1.0.0

Reset (type alias)

Signature

export type Reset = typeof Reset

Added in v1.0.0

type ids

RefreshableTypeId

Signature

export declare const RefreshableTypeId: typeof RefreshableTypeId

Added in v1.0.0

RefreshableTypeId (type alias)

Signature

export type RefreshableTypeId = typeof RefreshableTypeId

Added in v1.0.0

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0

WritableTypeId

Signature

export declare const WritableTypeId: typeof WritableTypeId

Added in v1.0.0

WritableTypeId (type alias)

Signature

export type WritableTypeId = typeof WritableTypeId

Added in v1.0.0

utils

RxResultFn (namespace)

Added in v1.0.0

ArgToVoid (type alias)

Signature

export type ArgToVoid<Arg> = Arg extends infer A ? (unknown extends A ? void : A extends undefined ? void : A) : never

Added in v1.0.0