Bin

data class Bin<T>(val range: ClosedRange<Double>, val items: List<T>)(source)

A histogram bin containing the items that fall within a value range.

Bin boundaries follow the half-open interval convention: items are assigned to the bin whose range contains them as [start, end), except for the last bin which is [start, end]. Boundary values (values that fall exactly on an interior bin edge) are assigned to the higher bin via floor(index) arithmetic. As a result, range (a ClosedRange) may report contains(value) == true for boundary values that are actually assigned to the adjacent bin.

This is a stable value type: its property set (range, items) is fixed and will not change in future versions.

Example:

val bins = listOf(1.0, 2.0, 3.0, 4.0, 5.0).bin(2.5)
bins[0].range // 1.0..3.5
bins[0].count // number of items in this bin
bins[0].items // the actual items

Type Parameters

T

the type of items in the bin.

Constructors

Link copied to clipboard
constructor(range: ClosedRange<Double>, items: List<T>)

Properties

Link copied to clipboard
val count: Int

Returns the number of items in this bin.

Link copied to clipboard
val items: List<T>

the elements whose values fall within range.

Link copied to clipboard

the closed interval of values that this bin covers.