<A>(order: Order<A>): (
...elements: Array<A>
) => Effect.Effect<TxPriorityQueue<A>>Creates a TxPriorityQueue from variadic elements.
Example (Creating a priority queue from variadic values)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.make(Order.Number)(3, 1, 2)
const first = yield* TxPriorityQueue.take(pq)
console.log(first) // 1
})export const const make: <A>(
order: Order<A>
) => (
...elements: Array<A>
) => Effect.Effect<TxPriorityQueue<A>>
Creates a TxPriorityQueue from variadic elements.
Example (Creating a priority queue from variadic values)
import { Effect, Order, TxPriorityQueue } from "effect"
const program = Effect.gen(function*() {
const pq = yield* TxPriorityQueue.make(Order.Number)(3, 1, 2)
const first = yield* TxPriorityQueue.take(pq)
console.log(first) // 1
})
make = <function (type parameter) A in <A>(order: Order<A>): (...elements: Array<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>): (...elements: Array<A>) => Effect.Effect<TxPriorityQueue<A>>A>) => (...elements: A[]elements: interface Array<T>Array<function (type parameter) A in <A>(order: Order<A>): (...elements: Array<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>): (...elements: Array<A>) => Effect.Effect<TxPriorityQueue<A>>A>> =>
const fromIterable: {
<A>(order: Order<A>): (
iterable: Iterable<A>
) => Effect.Effect<TxPriorityQueue<A>>
<A>(
order: Order<A>,
iterable: Iterable<A>
): Effect.Effect<TxPriorityQueue<A>>
}
fromIterable(order: Order<A>order, elements: A[]elements)