Skip to content

Instantly share code, notes, and snippets.

@akanehara
Last active December 12, 2015 06:49
Show Gist options
  • Save akanehara/4731702 to your computer and use it in GitHub Desktop.
Save akanehara/4731702 to your computer and use it in GitHub Desktop.
GinqにMemoizeIterator があれば…
<?php
// 巻き戻しできないデータソース
function dbFetch() {
...
yield $row;
...
}
// ごにょごにょしたのをメモ化
// もちろんこの段階ではまだ何も起らない
$rows = Ginq::from(dbFetch())
->zip(Ginq::range(1),
function($row, $no) { … })
->memoize();
// 問い合わせ
// (述語が見つかるまでフェッチ&キャッシュされる)
$isFoo = $rows->any(function($r) { … });
// レンダリング
// ここまでフェッチ済みの行はキャッシュが使われる
$template->render($rows);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment