« Home » « Learn » « Download » « Github »

logo

Cello High Level C

Methods

filter

#define filter(I, F)

Construct a Filter object on the stack over iterable I with filter function F.

Examples

Usage

var greater_than_two(var x) {
  return c_int(x) > 2 ? x : NULL;
}

var x = new(Array, Int, $I(0), $I(5), $I(2), $I(9));

foreach (n in filter(x, $(Function, greater_than_two))) {
  show(n); /* 5, 9 */
}

Usage 2

var mem_hello(var x) {
  return mem(x, $S("Hello")) ? x : NULL;
}

var x = new(Tuple, 
  $S("Hello World"), $S("Hello Dan"), 
  $S("Bonjour"));

var y = new(Tuple);
assign(y, filter(x, $(Function, mem_hello)));
show(y); /* tuple("Hello World", "Hello Dan") */

Filter


Filtered Iterable

The Filter type can be used to filter the results of some iterable. Given a callable object Filter iterable returns only those items in the original iterable for where calling the function returns a non-NULL value.

Definition

struct Filter {
  var iter;
  var func;
};

Derives

Implements

  • Docname brief description definition
  • Getget set mem rem key_type val_type
  • Iterforeach iter_init iter_next iter_type
  • Newnew del construct destruct

Back