-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation for Core nearly all in place.
- Loading branch information
1 parent
d1eec84
commit c2fb782
Showing
7 changed files
with
112 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
<?php include "lib/Recess/Recess.php"; use Recess\Core\Hash; | ||
|
||
// ==== Use a Hash like PHP's built-in array | ||
$hash = new Hash(array('key' => 'value')); | ||
echo $hash['key']; // output: value | ||
$hash[] = 'foo'; | ||
$hash['bar'] = 'baz'; | ||
echo $hash['key'],"\n"; | ||
//> value | ||
|
||
// ==== Construct Hash with values | ||
$hash = new Hash(1,2,3,4); | ||
print_r($hash->map(function($x) { return $x*$x; })); | ||
// array (1,4,9,16); | ||
echo "$hash[0] $hash[1] $hash[2] $hash[3]\n"; | ||
//> 1 2 3 4 | ||
|
||
$hash = new Hash(1,2,3); | ||
foreach($hash as $element) { | ||
echo "$element,"; | ||
} | ||
// 1,2,3, | ||
// ==== Use higher-order methods | ||
$hash->map(function($x) { return $x*$x; }) | ||
->filter(function($x) { return $x % 2 === 0; }) | ||
->each(function($x) { echo "$x "; }); | ||
//> 4 16 | ||
$sum = $hash->reduce(function($x,$y) { return $x + $y; }, 1); | ||
echo "\nSum: $sum\n"; | ||
//> Sum: 10 |