<A>(self: TxPriorityQueue<A>): Effect.Effect<number>Returns the number of elements in the queue.
Example (Getting the queue size)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [1, 2, 3])
const s = yield* TxPriorityQueue.size(pq)
console.log(s) // 3
})export const const size: <A>(
self: TxPriorityQueue<A>
) => Effect.Effect<number>
Returns the number of elements in the queue.
Example (Getting the queue size)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [1, 2, 3])
const s = yield* TxPriorityQueue.size(pq)
console.log(s) // 3
})
size = <function (type parameter) A in <A>(self: TxPriorityQueue<A>): Effect.Effect<number>A>(self: TxPriorityQueue<A>(parameter) self: {
ref: TxRef.TxRef<Chunk<A>>;
ord: Order<A>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface TxPriorityQueue<in out A>A transactional priority queue backed by a sorted Chunk.
Details
Elements are stored in ascending order according to the Order provided at
construction time. take returns the smallest element, peek observes it
without removing.
Example (Dequeuing values by priority)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.empty<number>(Order.Number)
yield* TxPriorityQueue.offer(pq, 3)
yield* TxPriorityQueue.offer(pq, 1)
yield* TxPriorityQueue.offer(pq, 2)
const first = yield* TxPriorityQueue.take(pq)
console.log(first) // 1
})
TxPriorityQueue<function (type parameter) A in <A>(self: TxPriorityQueue<A>): Effect.Effect<number>A>): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<number> => import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(import TxRefTxRef.const get: <A>(
self: TxRef<A>
) => Effect.Effect<A>
Reads the current value of the TxRef.
When to use
Use to read the current value of a TxRef.
Example (Reading transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
const counter = yield* TxRef.make(42)
// Read the value within a transaction
const value = yield* Effect.tx(
TxRef.get(counter)
)
console.log(value) // 42
})
get(self: TxPriorityQueue<A>(parameter) self: {
ref: TxRef.TxRef<Chunk<A>>;
ord: Order<A>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.TxPriorityQueue<A>.ref: TxRef.TxRef<Chunk<A>>(property) TxPriorityQueue<A>.ref: {
version: number;
pending: Map<unknown, () => void>;
value: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
ref), import CC.const size: <A>(self: Chunk<A>) => numberRetrieves the size of the chunk.
Example (Getting chunk size)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
console.log(Chunk.size(chunk)) // 3
size)