yamasushi(2013/03/26 04:33:25 UTC)OpenSearch互換のAPIにアクセスするときのパターンを抽出しました。
; Opensearch的なアクセスをする列を生成する
; gunfoldに似せたもの
; %unfold ... unfoldする関数
; %nullseq ... 空のseq
; n .... 取得するアイテム単位取得数(ページあたりのアイテム数)
; p .... seedから総数を取得する関数
; f .... seedから値を取得する関数
; g .... アイテム単位取得数と要素indexからseedを取得する関数
; :key
; start-index ..... indexの開始番号(デフォルトは1)
; 0ベースの場合もある
(define (opendata-%seq%
%unfold %null n p f g :key (start-index 1))
; %unfoldのシードは (index . seed)にする
(let* [ [ seed ($ cons start-index $ g n start-index ) ] [total ($ p $ cdr seed) ] ]
;#?=total
(if (and total (> total 0) )
(%unfold
(^s (not s) )
(^s ($ f $ cdr s))
(^s (and-let* [ [next (+ (car s) n)] [total ($ p $ cdr s)] ]
(if (< (- next start-index) total )
(cons next (g n next) )
#f ) ) )
seed )
%null ) ) )