Home

elementcountp

Elementcountp is a term used in programming to denote a function or operation that counts the number of elements in a collection that satisfy a given predicate p. The name is descriptive: it combines element counting with a predicate function, and it is commonly used in tutorials and pseudocode to illustrate higher-order functions.

Definition: elementcountp takes two arguments: a predicate p and a collection coll. It returns the number of

Signature examples: In a Lisp-like notation: (elementcountp pred coll). In Python-like pseudocode: def elementcountp(pred, coll): return

Semantics and complexity: The operation is typically linear in the size of the input collection, O(n). It

Variants: Some libraries may overload elementcountp to accept a comparison value, or to count elements equal

Examples: elementcountp(is_even, [1, 2, 3, 4, 5]) might return 2 in languages where is_even is a valid

Notes: As naming varies, some languages provide built-in count-with-predicate facilities under different names. elementcountp serves as

elements
x
in
coll
for
which
p(x)
evaluates
to
true.
The
predicate
is
typically
a
function
that
accepts
a
single
argument
and
returns
a
boolean.
sum(1
for
x
in
coll
if
pred(x)).
does
not
modify
the
input
collection.
It
should
handle
empty
collections
by
returning
0.
Some
implementations
may
support
streaming
collections
to
avoid
materializing
intermediate
results.
to
a
given
value
without
a
predicate,
or
to
count
with
an
index-aware
predicate.
There
are
related
functions
such
as
count,
filter,
and
reduce,
which
offer
alternative
ways
to
express
the
same
idea.
predicate.
Different
languages
will
have
different
syntax,
but
the
underlying
concept
remains
the
same:
tallying
elements
that
satisfy
a
condition.
a
concise,
descriptive
abstraction
for
this
common
data-processing
operation.