(by: number): (self: Duration) => Duration
(self: Duration, by: number): DurationDivides a Duration by a number using fallback rules instead of returning
an Option.
When to use
Use when dividing a Duration should return Duration.zero or signed
infinity for invalid cases instead of forcing callers to handle Option.none.
Details
Non-finite divisors return Duration.zero. Division by positive or negative
zero can produce signed infinity for non-zero finite durations, while zero
or infinite durations divided by zero produce Duration.zero.
Nanosecond-backed durations return Duration.zero when the divisor cannot
be converted to a bigint.
Example (Dividing durations unsafely)
import { Duration } from "effect"
const half = Duration.divideUnsafe(Duration.seconds(10), 2)
console.log(Duration.toSeconds(half)) // 5
const infinite = Duration.divideUnsafe(Duration.seconds(10), 0)
console.log(Duration.toMillis(infinite)) // Infinityexport const const divideUnsafe: {
(by: number): (self: Duration) => Duration
(self: Duration, by: number): Duration
}
Divides a Duration by a number using fallback rules instead of returning
an Option.
When to use
Use when dividing a Duration should return Duration.zero or signed
infinity for invalid cases instead of forcing callers to handle Option.none.
Details
Non-finite divisors return Duration.zero. Division by positive or negative
zero can produce signed infinity for non-zero finite durations, while zero
or infinite durations divided by zero produce Duration.zero.
Nanosecond-backed durations return Duration.zero when the divisor cannot
be converted to a bigint.
Example (Dividing durations unsafely)
import { Duration } from "effect"
const half = Duration.divideUnsafe(Duration.seconds(10), 2)
console.log(Duration.toSeconds(half)) // 5
const infinite = Duration.divideUnsafe(Duration.seconds(10), 0)
console.log(Duration.toMillis(infinite)) // Infinity
divideUnsafe: {
(by: numberby: number): (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) => Duration
(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, by: numberby: number): Duration
} = dual<(...args: Array<any>) => any, (self: Duration, by: number) => Duration>(arity: 2, body: (self: Duration, by: number) => Duration): ((...args: Array<any>) => any) & ((self: Duration, by: number) => Duration) (+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: 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, by: numberby: number): Duration => {
if (!var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.isFinite(number: unknown): booleanReturns true if passed value is finite.
Unlike the global isFinite, Number.isFinite doesn't forcibly convert the parameter to a
number. Only finite values of the type number, result in true.
isFinite(by: numberby)) return const zero: Durationconst zero: {
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;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero
return const match: {
<A, B, C, D = C>(options: {
readonly onMillis: (millis: number) => A
readonly onNanos: (nanos: bigint) => B
readonly onInfinity: () => C
readonly onNegativeInfinity?: () => D
}): (self: Duration) => A | B | C | D
<A, B, C, D = C>(
self: Duration,
options: {
readonly onMillis: (millis: number) => A
readonly onNanos: (nanos: bigint) => B
readonly onInfinity: () => C
readonly onNegativeInfinity?: () => D
}
): A | B | C | D
}
match(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, {
onMillis: (millis: number) => DurationonMillis: (millis: numbermillis) => const make: (
input: number | bigint
) => Duration
make(millis: numbermillis / by: numberby),
onNanos: (nanos: bigint) => DurationonNanos: (nanos: bigintnanos) => {
if (var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.is(value1: any, value2: any): booleanReturns true if the values are the same value, false otherwise.
is(by: numberby, 0) || var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.is(value1: any, value2: any): booleanReturns true if the values are the same value, false otherwise.
is(by: numberby, -0)) {
if (nanos: bigintnanos === const bigint0: bigintbigint0) return const zero: Durationconst zero: {
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;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero
// match IEEE 754: same sign → +infinity, different sign → -infinity
const const positiveNanos: booleanpositiveNanos = nanos: bigintnanos > const bigint0: bigintbigint0
const const positiveZero: booleanpositiveZero = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.is(value1: any, value2: any): booleanReturns true if the values are the same value, false otherwise.
is(by: numberby, 0)
return (const positiveNanos: booleanpositiveNanos === const positiveZero: booleanpositiveZero) ? const infinity: Durationconst infinity: {
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;
}
A Duration representing infinite time.
Example (Referencing infinite duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.infinity)) // Infinity
infinity : const negativeInfinity: Durationconst negativeInfinity: {
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;
}
A Duration representing negative infinite time.
Example (Referencing negative infinite duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.negativeInfinity)) // -Infinity
negativeInfinity
}
try {
return const make: (
input: number | bigint
) => Duration
make(nanos: bigintnanos / var BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
BigInt(by: numberby))
} catch {
return const zero: Durationconst zero: {
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;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero
}
},
onInfinity: () => DurationonInfinity: () => by: numberby > 0 ? const infinity: Durationconst infinity: {
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;
}
A Duration representing infinite time.
Example (Referencing infinite duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.infinity)) // Infinity
infinity : by: numberby < 0 ? const negativeInfinity: Durationconst negativeInfinity: {
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;
}
A Duration representing negative infinite time.
Example (Referencing negative infinite duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.negativeInfinity)) // -Infinity
negativeInfinity : const zero: Durationconst zero: {
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;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero,
onNegativeInfinity?: (() => Duration) | undefinedonNegativeInfinity: () => by: numberby > 0 ? const negativeInfinity: Durationconst negativeInfinity: {
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;
}
A Duration representing negative infinite time.
Example (Referencing negative infinite duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.negativeInfinity)) // -Infinity
negativeInfinity : by: numberby < 0 ? const infinity: Durationconst infinity: {
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;
}
A Duration representing infinite time.
Example (Referencing infinite duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.infinity)) // Infinity
infinity : const zero: Durationconst zero: {
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;
}
A Duration representing zero time.
Example (Referencing the zero duration)
import { Duration } from "effect"
console.log(Duration.toMillis(Duration.zero)) // 0
zero
})
}
)