Last active
December 12, 2015 06:49
-
-
Save akanehara/4731702 to your computer and use it in GitHub Desktop.
GinqにMemoizeIterator があれば…
This file contains hidden or 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
<?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