Example #1
0
 public function testMap()
 {
     $this->properties->map(function ($key, $item) {
         return "mapped_" . $item;
     });
     $this->assertEquals(['foo1' => 'mapped_bar1', 'foo2' => 'mapped_bar2'], $this->properties->toArray());
 }
Example #2
0
 public function test_letter_frequency()
 {
     $words = new Map(['aardvark', 'roads', 'sparks']);
     $freqs = $words->map(function ($word) {
         return new MapOfInts(count_chars($word, 1));
     })->reduce(function ($totals, $counts) {
         return $totals->translate($counts);
     }, new MapOfInts())->rekey('chr($_1)');
     $this->assertSame(['a' => 5, 'd' => 2, 'k' => 2, 'r' => 4, 'v' => 1, 'o' => 1, 's' => 3, 'p' => 1], $freqs->toArray());
 }