<A>(order: Order<A>): (
iterable: Iterable<A>
) => Effect.Effect<TxPriorityQueue<A>>
<A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<
TxPriorityQueue<A>
>Creates a TxPriorityQueue from an iterable of elements.
Example (Creating a priority queue from an iterable)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
const first = yield* TxPriorityQueue.take(pq)
console.log(first) // 1
})export const const fromIterable: {
<A>(order: Order<A>): (
iterable: Iterable<A>
) => Effect.Effect<TxPriorityQueue<A>>
<A>(
order: Order<A>,
iterable: Iterable<A>
): Effect.Effect<TxPriorityQueue<A>>
}
Creates a TxPriorityQueue from an iterable of elements.
Example (Creating a priority queue from an iterable)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.fromIterable(Order.Number, [3, 1, 2])
const first = yield* TxPriorityQueue.take(pq)
console.log(first) // 1
})
fromIterable: {
<function (type parameter) A in <A>(order: Order<A>): (iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<A>>A>(order: Order<A>order: interface Order<in A>Represents a total ordering for values of type A.
When to use
Use when you need to define how values of a type are compared.
Details
An order returns -1 when the first value is less than the second, 0 when
the values are equal according to this ordering, and 1 when the first value
is greater than the second. It must satisfy total ordering laws: totality,
antisymmetry, and transitivity.
Example (Defining a custom Order)
import { Order } from "effect"
const byAge: Order.Order<{ name: string; age: number }> = (self, that) => {
if (self.age < that.age) return -1
if (self.age > that.age) return 1
return 0
}
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 25 }
console.log(byAge(person1, person2)) // 1
Order<function (type parameter) A in <A>(order: Order<A>): (iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<A>>A>): (iterable: Iterable<A>iterable: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(order: Order<A>): (iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<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 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>(order: Order<A>): (iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<A>>A>>
<function (type parameter) A in <A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>(order: Order<A>order: interface Order<in A>Represents a total ordering for values of type A.
When to use
Use when you need to define how values of a type are compared.
Details
An order returns -1 when the first value is less than the second, 0 when
the values are equal according to this ordering, and 1 when the first value
is greater than the second. It must satisfy total ordering laws: totality,
antisymmetry, and transitivity.
Example (Defining a custom Order)
import { Order } from "effect"
const byAge: Order.Order<{ name: string; age: number }> = (self, that) => {
if (self.age < that.age) return -1
if (self.age > that.age) return 1
return 0
}
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 25 }
console.log(byAge(person1, person2)) // 1
Order<function (type parameter) A in <A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>, iterable: Iterable<A>iterable: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<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 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>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>>
} = dual<(...args: Array<any>) => any, <A>(order: Order<A>, iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<A>>>(arity: 2, body: <A>(order: Order<A>, iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<A>>): ((...args: Array<any>) => any) & (<A>(order: Order<A>, iterable: Iterable<A>) => Effect.Effect<TxPriorityQueue<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>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>(order: Order<A>order: interface Order<in A>Represents a total ordering for values of type A.
When to use
Use when you need to define how values of a type are compared.
Details
An order returns -1 when the first value is less than the second, 0 when
the values are equal according to this ordering, and 1 when the first value
is greater than the second. It must satisfy total ordering laws: totality,
antisymmetry, and transitivity.
Example (Defining a custom Order)
import { Order } from "effect"
const byAge: Order.Order<{ name: string; age: number }> = (self, that) => {
if (self.age < that.age) return -1
if (self.age > that.age) return 1
return 0
}
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 25 }
console.log(byAge(person1, person2)) // 1
Order<function (type parameter) A in <A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>, iterable: Iterable<A>iterable: interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<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 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>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>> => {
const const arr: A[]arr = var Array: ArrayConstructorArray.ArrayConstructor.from<A>(iterable: Iterable<A> | ArrayLike<A>): A[] (+3 overloads)Creates an array from an iterable object.
from(iterable: Iterable<A>iterable).Array<A>.sort(compareFn?: ((a: A, b: A) => number) | undefined): A[]Sorts an array in place.
This method mutates the array and returns a reference to the same array.
sort((a: Aa, b: Ab) => order: Order<A>order(a: Aa, b: Ab))
return 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 make: <Chunk<A>>(initial: Chunk<A>) => Effect.Effect<TxRef.TxRef<Chunk<A>>, never, never>Creates a new TxRef with the specified initial value.
When to use
Use to create a TxRef inside an Effect workflow.
Example (Creating transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
// Create a transactional reference with initial value
const counter = yield* TxRef.make(0)
const name = yield* TxRef.make("Alice")
// Use in transactions
yield* Effect.tx(Effect.gen(function*() {
yield* TxRef.set(counter, 42)
yield* TxRef.set(name, "Bob")
}))
console.log(yield* TxRef.get(counter)) // 42
console.log(yield* TxRef.get(name)) // "Bob"
})
make<interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) A in <A>(order: Order<A>, iterable: Iterable<A>): Effect.Effect<TxPriorityQueue<A>>A>>(import CC.const fromIterable: <A>(
self: Iterable<A>
) => Chunk<A>
Creates a new Chunk from an iterable collection of values.
Example (Creating chunks from iterables)
import { Chunk } from "effect"
const chunk = Chunk.fromIterable([1, 2, 3])
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
fromIterable(const arr: A[]arr)),
(ref: TxRef.TxRef<Chunk<A>>(parameter) 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) => const makeTxPriorityQueue: <A>(
ref: TxRef.TxRef<Chunk<A>>,
ord: Order<A>
) => TxPriorityQueue<A>
makeTxPriorityQueue(ref: TxRef.TxRef<Chunk<A>>(parameter) 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, order: Order<A>order)
)
}
)