Skip to content

Instantly share code, notes, and snippets.

@deizel
Created August 13, 2015 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deizel/2d85a6cb62e5bb92c76e to your computer and use it in GitHub Desktop.
Save deizel/2d85a6cb62e5bb92c76e to your computer and use it in GitHub Desktop.
Example of CakePHP Collection
<?php
$countries = ['Denmark', 'Netherlands', 'France'];
$types = ['Italian', 'Japanese', 'Chinese'];
collection($countries)
->unfold(function ($country) use ($types) {
foreach ($types as $type) {
yield $country => $type;
}
})
->map(function ($type, $country) use ($yelpApi) {
return $yelpApi->getPopularPlaces($country, $type);
})
->filter(function ($result) {
return empty($result['error']);
})
->unfold(function ($result, $country) {
foreach ($result['places'] as $place) {
yield $country => $place;
}
})
->toList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment