(iterable: Iterable<number>): ReadonlyArray<number>Creates histogram bucket boundaries from an iterable set of values.
Details
Processes any iterable of numbers by removing duplicates, filtering out non-positive values, and automatically appending positive infinity as the final boundary.
Example (Creating boundaries from values)
import { Data, Effect, Metric } from "effect"
class BoundaryError extends Data.TaggedError("BoundaryError")<{
readonly operation: string
}> {}
// Create boundaries from an array of custom values
const customBoundaries = Metric.boundariesFromIterable([
10,
25,
50,
100,
250,
500,
1000
])
console.log(customBoundaries) // [10, 25, 50, 100, 250, 500, 1000, Infinity]
// Automatically removes duplicates and negative values
const messyBoundaries = Metric.boundariesFromIterable([
-5,
0,
10,
10,
25,
25,
50,
-1
])
console.log(messyBoundaries) // [10, 25, 50, Infinity]
// Works with any iterable (Set, generator functions, etc.)
const setBoundaries = Metric.boundariesFromIterable(
new Set([100, 200, 300, 200, 100])
)
console.log(setBoundaries) // [100, 200, 300, Infinity]
// Use with histogram metric
const responseTimeHistogram = Metric.histogram("response_times", {
description: "API response time distribution",
boundaries: customBoundaries
})
const program = Effect.gen(function*() {
yield* Metric.update(responseTimeHistogram, 75) // Goes in 50-100ms bucket
yield* Metric.update(responseTimeHistogram, 150) // Goes in 100-250ms bucket
const value = yield* Metric.value(responseTimeHistogram)
return value
})export const const boundariesFromIterable: (
iterable: Iterable<number>
) => ReadonlyArray<number>
Creates histogram bucket boundaries from an iterable set of values.
Details
Processes any iterable of numbers by removing duplicates, filtering out
non-positive values, and automatically appending positive infinity as the
final boundary.
Example (Creating boundaries from values)
import { Data, Effect, Metric } from "effect"
class BoundaryError extends Data.TaggedError("BoundaryError")<{
readonly operation: string
}> {}
// Create boundaries from an array of custom values
const customBoundaries = Metric.boundariesFromIterable([
10,
25,
50,
100,
250,
500,
1000
])
console.log(customBoundaries) // [10, 25, 50, 100, 250, 500, 1000, Infinity]
// Automatically removes duplicates and negative values
const messyBoundaries = Metric.boundariesFromIterable([
-5,
0,
10,
10,
25,
25,
50,
-1
])
console.log(messyBoundaries) // [10, 25, 50, Infinity]
// Works with any iterable (Set, generator functions, etc.)
const setBoundaries = Metric.boundariesFromIterable(
new Set([100, 200, 300, 200, 100])
)
console.log(setBoundaries) // [100, 200, 300, Infinity]
// Use with histogram metric
const responseTimeHistogram = Metric.histogram("response_times", {
description: "API response time distribution",
boundaries: customBoundaries
})
const program = Effect.gen(function*() {
yield* Metric.update(responseTimeHistogram, 75) // Goes in 50-100ms bucket
yield* Metric.update(responseTimeHistogram, 150) // Goes in 100-250ms bucket
const value = yield* Metric.value(responseTimeHistogram)
return value
})
boundariesFromIterable = (iterable: Iterable<number>iterable: interface Iterable<T, TReturn = any, TNext = any>Iterable<number>): interface ReadonlyArray<T>ReadonlyArray<number> =>
import ArrArr.append(import ArrArr.filter(new var Set: SetConstructor
new <number>(iterable?: Iterable<number> | null | undefined) => Set<number> (+1 overload)
Set(iterable: Iterable<number>iterable), (n: anyn) => n: anyn > 0), var Number: NumberConstructorAn object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number.NumberConstructor.POSITIVE_INFINITY: numberA value greater than the largest number that can be represented in JavaScript.
JavaScript displays POSITIVE_INFINITY values as infinity.
POSITIVE_INFINITY)