(times: number): (self: Duration) => Duration
(self: Duration, times: number): DurationReturns a Duration multiplied by a number.
Details
For nanosecond-backed durations, the multiplier must be convertible to a
bigint; fractional or non-finite multipliers can throw. Infinite
durations return positive infinity, negative infinity, or zero depending on
the multiplier sign.
Example (Multiplying durations)
import { Duration } from "effect"
const doubled = Duration.times(Duration.seconds(5), 2)
console.log(Duration.toSeconds(doubled)) // 10export const const times: {
(times: number): (self: Duration) => Duration
(self: Duration, times: number): Duration
}
Returns a Duration multiplied by a number.
Details
For nanosecond-backed durations, the multiplier must be convertible to a
bigint; fractional or non-finite multipliers can throw. Infinite
durations return positive infinity, negative infinity, or zero depending on
the multiplier sign.
Example (Multiplying durations)
import { Duration } from "effect"
const doubled = Duration.times(Duration.seconds(5), 2)
console.log(Duration.toSeconds(doubled)) // 10
times: {
(times: numbertimes: 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, times: numbertimes: number): Duration
} = dual<(...args: Array<any>) => any, (self: Duration, times: number) => Duration>(arity: 2, body: (self: Duration, times: number) => Duration): ((...args: Array<any>) => any) & ((self: Duration, times: 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, times: numbertimes: number): Duration =>
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 * times: numbertimes),
onNanos: (nanos: bigint) => DurationonNanos: (nanos: bigintnanos) => const make: (
input: number | bigint
) => Duration
make(nanos: bigintnanos * var BigInt: BigIntConstructor
;(value: bigint | boolean | number | string) =>
bigint
BigInt(times: numbertimes)),
onInfinity: () => DurationonInfinity: () => times: numbertimes > 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 : times: numbertimes < 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: () => times: numbertimes > 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 : times: numbertimes < 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
})
)