bundles / papyri latest / papyri / examples / higher_order
function
papyri.examples:higher_order
source: /papyri/examples.py :675
Signature
def higher_order ( fn : Callable[[int], int] , items : list[int] ) → list[int] Summary
Apply fn to every element of items.
Extended Summary
Demonstrates a Callable annotation. If you would rather consume an iterator, simple_generator and fibonacci produce the kind of stream this function maps over.
Parameters
fn: Callable[[int], int]Unary function from
inttoint.items: list of intInput values.
Returns
: list of int[fn(x) for x in items].
Examples
higher_order(lambda x: x * x, [1, 2, 3])
✓See also
- fibonacci
Another integer-producing generator.
- simple_generator
A generator-based alternative input.
Aliases
-
papyri.examples.higher_order