Ejemplo n.º 1
0
# the H() function does not accept the KEY => VALUE syntax, but instead accepts a parameter list of alternating KEY, VALUE, parameters
# the new H(array(...)) syntax does accept KEY => VALUE notation but with the drawback that KEYs must be defined using native types.

$h = H(S("SATURN"), 1, 'hello', 2, 'goodbye', 3, 'fatty', 0);
$h = new H(array("SATURN" => 1, 'hello' => 2, 'goodbye' => 3, 'fatty' => 0));

echo "hash = ".$h."\n";

# the each() iterator for hashes pass a 2-pair array containing at offset 0 the KEY and offset 1 the VALUE i.e. A($key, $value)

$h->each(function($x) { echo ">> each() $x <<\n"; });

# the each_pair() function is an alias of each_with_index() passing each key,value pair to the callback function

$h->each_pair(function($x,$y) { echo ">> each_pair() key={$x} value={$y} <<\n"; });

# there are many other methods
# please refer to the code within the lib/ directory for now
# each class is broken up into seperate files

function quicksort($xs) {

	if($xs->count() < 2)
		return $xs;

	$p = $xs->head();

	$fn = function($x) use($p) { return $x < $p; };

	return