(n: number): <A>(self: TxPriorityQueue<A>) => Effect.Effect<Array<A>>
<A>(self: TxPriorityQueue<A>, n: number): Effect.Effect<Array<A>>Takes up to n elements from the queue in priority order.
Example (Taking up to a limit)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [5, 3, 1, 4, 2])
const top2 = yield* TxPriorityQueue.takeUpTo(pq, 2)
console.log(top2) // [1, 2]
})export const const takeUpTo: {
(n: number): <A>(
self: TxPriorityQueue<A>
) => Effect.Effect<Array<A>>
<A>(
self: TxPriorityQueue<A>,
n: number
): Effect.Effect<Array<A>>
}
Takes up to n elements from the queue in priority order.
Example (Taking up to a limit)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [5, 3, 1, 4, 2])
const top2 = yield* TxPriorityQueue.takeUpTo(pq, 2)
console.log(top2) // [1, 2]
})
takeUpTo: {
(n: numbern: number): <function (type parameter) A in <A>(self: TxPriorityQueue<A>): Effect.Effect<Array<A>>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<Array<A>>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<interface Array<T>Array<function (type parameter) A in <A>(self: TxPriorityQueue<A>): Effect.Effect<Array<A>>A>>
<function (type parameter) A in <A>(self: TxPriorityQueue<A>, n: number): Effect.Effect<Array<A>>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>, n: number): Effect.Effect<Array<A>>A>, n: numbern: number): 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<interface Array<T>Array<function (type parameter) A in <A>(self: TxPriorityQueue<A>, n: number): Effect.Effect<Array<A>>A>>
} = dual<(...args: Array<any>) => any, <A>(self: TxPriorityQueue<A>, n: number) => Effect.Effect<Array<A>>>(arity: 2, body: <A>(self: TxPriorityQueue<A>, n: number) => Effect.Effect<Array<A>>): ((...args: Array<any>) => any) & (<A>(self: TxPriorityQueue<A>, n: number) => Effect.Effect<Array<A>>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(
2,
<function (type parameter) A in <A>(self: TxPriorityQueue<A>, n: number): Effect.Effect<Array<A>>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>, n: number): Effect.Effect<Array<A>>A>, n: numbern: number): 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<interface Array<T>Array<function (type parameter) A in <A>(self: TxPriorityQueue<A>, n: number): Effect.Effect<Array<A>>A>> =>
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 modify: {
<A, R>(
f: (
current: NoInfer<A>
) => [returnValue: R, newValue: A]
): (self: TxRef<A>) => Effect.Effect<R>
<A, R>(
self: TxRef<A>,
f: (
current: A
) => [returnValue: R, newValue: A]
): Effect.Effect<R>
}
modify(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, (chunk: Chunk<A>(parameter) chunk: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
chunk) => {
const const taken: Chunk<A>const taken: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
taken = import CC.const take: {
(n: number): <A>(self: Chunk<A>) => Chunk<A>
<A>(self: Chunk<A>, n: number): Chunk<A>
}
take(chunk: Chunk<A>(parameter) chunk: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
chunk, n: numbern)
const const rest: Chunk<A>const rest: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
rest = import CC.const drop: {
(n: number): <A>(self: Chunk<A>) => Chunk<A>
<A>(self: Chunk<A>, n: number): Chunk<A>
}
drop(chunk: Chunk<A>(parameter) chunk: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
chunk, n: numbern)
return [const taken: Chunk<A>const taken: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
taken, const rest: Chunk<A>const rest: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
rest]
}),
import CC.const toArray: <S extends Chunk<any>>(
self: S
) => S extends NonEmptyChunk<any>
? RA.NonEmptyArray<Chunk.Infer<S>>
: Array<Chunk.Infer<S>>
Converts a Chunk into an Array. If the provided Chunk is non-empty
(NonEmptyChunk), the function will return a NonEmptyArray, ensuring the
non-empty property is preserved.
Example (Converting chunks to mutable arrays)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
const array = Chunk.toArray(chunk)
console.log(array) // [1, 2, 3]
console.log(Array.isArray(array)) // true
// With empty chunk
const emptyChunk = Chunk.empty<number>()
console.log(Chunk.toArray(emptyChunk)) // []
toArray
)
)