<A, B, C>(
that: Duration,
options: {
readonly onMillis: (self: number, that: number) => A
readonly onNanos: (self: bigint, that: bigint) => B
readonly onInfinity: (self: Duration, that: Duration) => C
}
): (self: Duration) => A | B | C
<A, B, C>(
self: Duration,
that: Duration,
options: {
readonly onMillis: (self: number, that: number) => A
readonly onNanos: (self: bigint, that: bigint) => B
readonly onInfinity: (self: Duration, that: Duration) => C
}
): A | B | CPattern matches on two Durations, providing handlers that receive both values.
Example (Pattern matching on duration pairs)
import { Duration } from "effect"
const sum = Duration.matchPair(Duration.seconds(3), Duration.seconds(2), {
onMillis: (a, b) => a + b,
onNanos: (a, b) => Number(a + b),
onInfinity: () => Infinity
})
console.log(sum) // 5000export const const matchPair: {
<A, B, C>(
that: Duration,
options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
): (self: Duration) => A | B | C
<A, B, C>(
self: Duration,
that: Duration,
options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
): A | B | C
}
Pattern matches on two Durations, providing handlers that receive both values.
Example (Pattern matching on duration pairs)
import { Duration } from "effect"
const sum = Duration.matchPair(Duration.seconds(3), Duration.seconds(2), {
onMillis: (a, b) => a + b,
onNanos: (a, b) => Number(a + b),
onInfinity: () => Infinity
})
console.log(sum) // 5000
matchPair: {
<function (type parameter) A in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
A, function (type parameter) B in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
B, function (type parameter) C in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
C>(
that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that: Duration,
options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options: {
readonly onMillis: (self: number, that: number) => AonMillis: (self: numberself: number, that: numberthat: number) => function (type parameter) A in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
A
readonly onNanos: (self: bigint, that: bigint) => BonNanos: (self: bigintself: bigint, that: bigintthat: bigint) => function (type parameter) B in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
B
readonly onInfinity: (self: Duration, that: Duration) => ConInfinity: (self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: Duration, that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that: Duration) => function (type parameter) C in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
C
}
): (self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: Duration) => function (type parameter) A in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
A | function (type parameter) B in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
B | function (type parameter) C in <A, B, C>(that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): (self: Duration) => A | B | C
C
<function (type parameter) A in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
A, function (type parameter) B in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
B, function (type parameter) C in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
C>(
self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: Duration,
that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that: Duration,
options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options: {
readonly onMillis: (self: number, that: number) => AonMillis: (self: numberself: number, that: numberthat: number) => function (type parameter) A in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
A
readonly onNanos: (self: bigint, that: bigint) => BonNanos: (self: bigintself: bigint, that: bigintthat: bigint) => function (type parameter) B in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
B
readonly onInfinity: (self: Duration, that: Duration) => ConInfinity: (self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: Duration, that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that: Duration) => function (type parameter) C in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
C
}
): function (type parameter) A in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
A | function (type parameter) B in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
B | function (type parameter) C in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
C
} = dual<(...args: Array<any>) => any, <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}) => A | B | C>(arity: 3, body: <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}) => A | B | C): ((...args: Array<any>) => any) & (<A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}) => A | B | C) (+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(3, <function (type parameter) A in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
A, function (type parameter) B in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
B, function (type parameter) C in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
C>(
self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: Duration,
that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that: Duration,
options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options: {
readonly onMillis: (self: number, that: number) => AonMillis: (self: numberself: number, that: numberthat: number) => function (type parameter) A in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
A
readonly onNanos: (self: bigint, that: bigint) => BonNanos: (self: bigintself: bigint, that: bigintthat: bigint) => function (type parameter) B in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
B
readonly onInfinity: (self: Duration, that: Duration) => ConInfinity: (self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self: Duration, that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that: Duration) => function (type parameter) C in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
C
}
): function (type parameter) A in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
A | function (type parameter) B in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
B | function (type parameter) C in <A, B, C>(self: Duration, that: Duration, options: {
readonly onMillis: (self: number, that: number) => A;
readonly onNanos: (self: bigint, that: bigint) => B;
readonly onInfinity: (self: Duration, that: Duration) => C;
}): A | B | C
C => {
if (
self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Duration.value: DurationValuevalue._tag: | "Millis"
| "Nanos"
| "Infinity"
| "NegativeInfinity"
_tag === "Infinity" || self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Duration.value: DurationValuevalue._tag: "Millis" | "Nanos" | "NegativeInfinity"_tag === "NegativeInfinity" ||
that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that.Duration.value: DurationValuevalue._tag: | "Millis"
| "Nanos"
| "Infinity"
| "NegativeInfinity"
_tag === "Infinity" || that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that.Duration.value: DurationValuevalue._tag: "Millis" | "Nanos" | "NegativeInfinity"_tag === "NegativeInfinity"
) return options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options.onInfinity: (self: Duration, that: Duration) => ConInfinity(self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self, that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that)
if (self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Duration.value: DurationValuevalue._tag: "Millis" | "Nanos"_tag === "Millis") {
return that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that.Duration.value: DurationValuevalue._tag: "Millis" | "Nanos"_tag === "Millis"
? options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options.onMillis: (self: number, that: number) => AonMillis(self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Duration.value: DurationValuevalue.millis: numbermillis, that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that.Duration.value: DurationValuevalue.millis: numbermillis)
: options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options.onNanos: (self: bigint, that: bigint) => BonNanos(const toNanosUnsafe: (
input: Input
) => bigint
Gets the duration in nanoseconds as a bigint.
When to use
Use when the duration is known to be finite and you need the nanosecond value
as a bigint.
Details
Millisecond-backed fractional durations are rounded to the nearest
nanosecond, with ties away from zero.
Gotchas
If the duration is infinite, it throws an error.
Example (Reading nanoseconds unsafely)
import { Duration } from "effect"
const duration = Duration.seconds(2)
const nanos = Duration.toNanosUnsafe(duration)
console.log(nanos) // 2000000000n
// Duration.toNanosUnsafe(Duration.infinity)
// throws Error: "Cannot convert infinite duration to nanos"
toNanosUnsafe(self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self), that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that.Duration.value: DurationValuevalue.nanos: bigintnanos)
} else {
return options: {
readonly onMillis: (
self: number,
that: number
) => A
readonly onNanos: (
self: bigint,
that: bigint
) => B
readonly onInfinity: (
self: Duration,
that: Duration
) => C
}
options.onNanos: (self: bigint, that: bigint) => BonNanos(self: Duration(parameter) self: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Duration.value: DurationValuevalue.nanos: bigintnanos, const toNanosUnsafe: (
input: Input
) => bigint
Gets the duration in nanoseconds as a bigint.
When to use
Use when the duration is known to be finite and you need the nanosecond value
as a bigint.
Details
Millisecond-backed fractional durations are rounded to the nearest
nanosecond, with ties away from zero.
Gotchas
If the duration is infinite, it throws an error.
Example (Reading nanoseconds unsafely)
import { Duration } from "effect"
const duration = Duration.seconds(2)
const nanos = Duration.toNanosUnsafe(duration)
console.log(nanos) // 2000000000n
// Duration.toNanosUnsafe(Duration.infinity)
// throws Error: "Cannot convert infinite duration to nanos"
toNanosUnsafe(that: Duration(parameter) that: {
value: DurationValue;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
that))
}
})