std.func

Provides functional abstractions.

  • Author: Edward Jones
  • Date: 2021-09-17

Source file

co_to_list

Creates a list from the values yielded from a coroutine.

  • Param c: Coroutine from which to extract values

Returns: A list of values returned from c

co_to_list = (c) -> ...

co_to_table

Constructs a table from a coroutine which yields {k,v} pairs.

  • Param c: Coroutine from which to extract kv-pairs

Returns: A table t such that for each {k,v} yielded from c, t\[k] = v

co_to_table = (c) -> ...

do_nothing

A function which does nothing.

do_nothing = -> ...

filter

Creates a coroutine whihc filters the values of a coroutine by a predicate.

  • Param p: A predicate
  • Param es: A coroutine which yields values to be filtered

Returns: A coroutine which yields the values of e of es which satisfy p(e) in the order they are yielded from es

filter = (p, es) -> ...

filter_list

Returns a list of values of a given list which satisfy a predicate.

  • Param p: A predicate
  • Param es: A list of values

Returns: A list of elements e of es which satisfy p(e)

filter_list = (p, es) -> ...

id

Identity function, takes a value and returns it.

  • Param x: Value to return

Returns: x

id = (x) -> ...

int

Creates a coroutine which yields the integers.

Returns: a coroutine which yields the integers

int = -> ...

key_list

Construct a list of keys from a table.

  • Param t: A table from which to extract keys

Returns: A list of keys in t

key_list = (t) -> ...

keys

Creates a coroutine which yields the keys of a table.

  • Param t: A table from which to extract keys

Returns: A coroutine which yields the keys of t

keys = (t) -> ...

kv_pairs

Creates a coroutine which yields {k,v} pairs of a table.

  • Param t: A table from which to extract key-value pairs

Returns: A coroutine which yields the kv-pairs of t

kv_pairs = (t) -> ...

map

Maps the values yielded by a coroutine with a given function.

  • Param f: The mapping function
  • Param es: The values to map

Returns: a coroutine which yields values f(e) for each e yielded from es

map = (f, es) -> ...

nat

Creates a coroutine which yields the natural numbers.

Returns: A coroutine which yields the natural numbers

nat = -> ...

seq

Creates a coroutine which yields the values of a sequence.

  • Param first: The first value of the sequence
  • Param last: The last value of the sequence
  • Param step: The difference between consecutive yielded values

Returns: A coroutine which yields values starting from first, in increments of step until last is reached

seq = (first, last, step) -> ...

take

Takes values from a coroutine whilst a predicate holds.

  • Param p: Predicate to check
  • Param es: From which to take values

Returns: A coroutine which yields values e of es for which p(e) holds, until the first which does not (at which point the coroutine finishes

take = (p, es) -> ...

value_list

Construct a list of values in a table.

  • Param t: A table from which to extract values

Returns: A list of the values in v

value_list = (t) -> ...

values

Creates a coroutine which yields the values of a table.

  • Param t: A table from which to extract values

Returns: A coroutine which yields the values of t

values = (t) -> ...

whole

Creates a coroutine which yields whole numbers.

Returns: A coroutine which yields the whole numbers

whole = -> ...