Skip to content

Instantly share code, notes, and snippets.

@hidenorigoto
Last active October 23, 2015 07:05
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 hidenorigoto/b4b45d310d0ac5dff4d6 to your computer and use it in GitHub Desktop.
Save hidenorigoto/b4b45d310d0ac5dff4d6 to your computer and use it in GitHub Desktop.
Haydnで結果に含めるかどうかを行ごとにオンデマンドで判定する
vendor/
composer.lock
{
"name": "hidenorigoto/haydn-select-returnnull",
"authors": [
{
"name": "hidenorigoto",
"email": "hidenorigoto@gmail.com"
}
],
"require": {
"quartet/haydn": "^1.3"
}
}
<?php
require_once __DIR__.'/vendor/autoload.php';
$data = [
['name' => 'りんご', 'available' => true],
['name' => 'バナナ', 'available' => false],
['name' => 'みかん', 'available' => true],
];
$set = new \Quartet\Haydn\Set(new \Quartet\Haydn\IO\Source\ArraySource('fruit', $data, new \Quartet\Haydn\IO\ColumnMapper\HashKeyColumnMapper()));
$set = new \Quartet\Haydn\Set\GroupingSet($set,
null,
function($row) {
return $row['available'] ?
new \Quartet\Haydn\Set(new \Quartet\Haydn\IO\Source\SingleRowSource('fruit', $row)) :
new \Quartet\Haydn\Set\EmptySet();
},
null
);
$result = $set->toArray();
var_dump($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment