(b: number): (self: number) => number
(self: number, b: number): numberCombines two hash values into a single hash value.
When to use
Use to build a hash for a composite value by folding together hash values for its parts.
Details
Supports both direct and pipeable usage. The implementation combines two
hash values with (self * 53) ^ b.
Example (Combining hash values)
import { Hash, pipe } from "effect"
// Can also be used with pipe
const hash1 = Hash.hash("hello")
const hash2 = Hash.hash("world")
// Combine two hash values
const combined = Hash.combine(hash2)(hash1)
console.log(combined)
const result = pipe(hash1, Hash.combine(hash2))export const const combine: {
(b: number): (self: number) => number
(self: number, b: number): number
}
Combines two hash values into a single hash value.
When to use
Use to build a hash for a composite value by folding together hash values for
its parts.
Details
Supports both direct and pipeable usage. The implementation combines two
hash values with (self * 53) ^ b.
Example (Combining hash values)
import { Hash, pipe } from "effect"
// Can also be used with pipe
const hash1 = Hash.hash("hello")
const hash2 = Hash.hash("world")
// Combine two hash values
const combined = Hash.combine(hash2)(hash1)
console.log(combined)
const result = pipe(hash1, Hash.combine(hash2))
combine: {
(b: numberb: number): (self: numberself: number) => number
(self: numberself: number, b: numberb: number): number
} = dual<(...args: Array<any>) => any, (self: number, b: number) => number>(arity: 2, body: (self: number, b: number) => number): ((...args: Array<any>) => any) & ((self: number, b: number) => number) (+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: numberself: number, b: numberb: number): number => (self: numberself * 53) ^ b: numberb)