<A>(order: Order.Order<A>): Combiner<A>Creates a Combiner that returns the larger of two values according to
the provided Order.
When to use
Use when you want to accumulate the maximum value across a collection or
build a Reducer that tracks the running maximum.
Details
The combiner compares values using the given Order. When values are equal,
it returns that (the second argument).
Example (Selecting the maximum of two numbers)
import { Combiner, Number } from "effect"
const Max = Combiner.max(Number.Order)
console.log(Max.combine(3, 1))
// Output: 3
console.log(Max.combine(1, 3))
// Output: 3export function function max<A>(
order: Order.Order<A>
): Combiner<A>
Creates a Combiner that returns the larger of two values according to
the provided Order.
When to use
Use when you want to accumulate the maximum value across a collection or
build a Reducer that tracks the running maximum.
Details
The combiner compares values using the given Order. When values are equal,
it returns that (the second argument).
Example (Selecting the maximum of two numbers)
import { Combiner, Number } from "effect"
const Max = Combiner.max(Number.Order)
console.log(Max.combine(3, 1))
// Output: 3
console.log(Max.combine(1, 3))
// Output: 3
max<function (type parameter) A in max<A>(order: Order.Order<A>): Combiner<A>A>(order: Order.Order<A>order: import OrderOrder.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 max<A>(order: Order.Order<A>): Combiner<A>A>): interface Combiner<A>Represents a strategy for combining two values of the same type A. A
Combiner contains a single combine method that takes two values and
returns a merged result. It does not include an identity/empty value; use
Reducer when you need one.
When to use
Use when you need to describe how two values of the same type
merge, pass a reusable combining strategy to library functions like
Struct.makeCombiner or Option.makeCombinerFailFast, or define the
combining step for a Reducer.
Example (Combining numbers with addition)
import { Combiner } from "effect"
const Sum = Combiner.make<number>((self, that) => self + that)
console.log(Sum.combine(3, 4))
// Output: 7
Combiner<function (type parameter) A in max<A>(order: Order.Order<A>): Combiner<A>A> {
return function make<A>(
combine: (self: A, that: A) => A
): Combiner<A>
Creates a Combiner from a binary function.
When to use
Use when you have a custom combining operation that is not covered by
the built-in constructors (min, max, first, last, constant).
Details
The returned combiner's combine method delegates to the provided function.
Any purity, associativity, or mutation behavior comes from that function.
Example (Multiplying numbers)
import { Combiner } from "effect"
const Product = Combiner.make<number>((self, that) => self * that)
console.log(Product.combine(3, 5))
// Output: 15
make((self: Aself, that: Athat) => order: Order.Order<A>order(self: Aself, that: Athat) === 1 ? self: Aself : that: Athat)
}