<A>(O: Order<A>): { (that: A): (self: A) => A; (self: A, that: A): A }Returns the maximum of two values according to the given order. If they are equal, returns the first argument.
When to use
Use when you need to select the larger of two values according to an
Order.
Details
Returns the value that compares as greater than or equal to the other value. If values are equal, the first argument is returned.
Example (Selecting the maximum value)
import { Order } from "effect"
const maxNumber = Order.max(Order.Number)
console.log(maxNumber(1, 2)) // 2
console.log(maxNumber(2, 1)) // 2
console.log(maxNumber(1, 1)) // 1export const const max: <A>(O: Order<A>) => {
(that: A): (self: A) => A
(self: A, that: A): A
}
Returns the maximum of two values according to the given order. If they are equal, returns the first argument.
When to use
Use when you need to select the larger of two values according to an
Order.
Details
Returns the value that compares as greater than or equal to the other value.
If values are equal, the first argument is returned.
Example (Selecting the maximum value)
import { Order } from "effect"
const maxNumber = Order.max(Order.Number)
console.log(maxNumber(1, 2)) // 2
console.log(maxNumber(2, 1)) // 2
console.log(maxNumber(1, 1)) // 1
max = <function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A>(type O: Order<A>O: 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>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A>): {
(that: Athat: function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A): (self: Aself: function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A) => function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A
(self: Aself: function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A, that: Athat: function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A): function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A
} => dual<(...args: Array<any>) => any, (self: A, that: A) => A>(arity: 2, body: (self: A, that: A) => A): ((...args: Array<any>) => any) & ((self: A, that: A) => 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, (self: Aself: function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A, that: Athat: function (type parameter) A in <A>(O: Order<A>): {
(that: A): (self: A) => A;
(self: A, that: A): A;
}
A) => self: Aself === that: Athat || type O: Order<A>O(self: Aself, that: Athat) > -1 ? self: Aself : that: Athat)