count

inline fun <T> Iterable<T>.count(from: Int = 0, to: Int = -1, predicate: (T) -> Boolean): Int(source)

Counts elements in this iterable that satisfy predicate within the index range starting at from.

Iteration stops when the current index reaches to (the element at index to is not counted). If from is greater than or equal to to, returns 0. Requires to to be at least -1.

Receiver

This iterable to count over in iteration order.

Return

The number of elements in the considered index range that satisfy predicate.

Parameters

from

The inclusive lower bound on element indices to consider. Defaults to 0.

to

The exclusive upper bound on element indices; iteration stops when this index is reached. Defaults to -1.

predicate

Called with each element whose index is at least from and strictly less than to; should return true for elements to count.

Type Parameters

T

The element type of this iterable.


inline fun <T> List<T>.count(from: Int = 0, to: Int = size, predicate: (T) -> Boolean): Int(source)

Counts elements in the sublist [from, to) that satisfy predicate.

Receiver

This list to count over.

Return

The number of elements in [from, to) that satisfy predicate.

Parameters

from

The inclusive start index of the range to count in. Defaults to 0.

to

The exclusive end index of the range to count in. Defaults to size.

predicate

Called with each element in the range; should return true for elements to count.

Type Parameters

T

The element type of this list.


inline fun IntArray.count(from: Int = 0, to: Int = size, predicate: (Int) -> Boolean): Int(source)

Counts elements in this int array that satisfy predicate within the index range [from, to].

Indices are clamped to [0, size]. The range is inclusive on both ends.

Receiver

This int array to count over.

Return

The number of elements in the range that satisfy predicate.

Parameters

from

The inclusive lower bound on indices to consider. Defaults to 0.

to

The inclusive upper bound on indices to consider. Defaults to size.

predicate

Called with each element in the range; should return true for elements to count.


inline fun BooleanArray.count(from: Int = 0, to: Int = size, predicate: (Boolean) -> Boolean): Int(source)

Counts elements in this boolean array that satisfy predicate within the index range [from, to].

Indices are clamped to [0, size]. The range is inclusive on both ends.

Receiver

This boolean array to count over.

Return

The number of elements in the range that satisfy predicate.

Parameters

from

The inclusive lower bound on indices to consider. Defaults to 0.

to

The inclusive upper bound on indices to consider. Defaults to size.

predicate

Called with each element in the range; should return true for elements to count.