-module(library).
-export([books/0]).
books() ->
from([book(<<"Structure and Interpretation of Computer Programs">>, <<"Harold Abelson">>),
book(<<"The Art of Computer Programming">>, <<"Donald Knuth">>),
book(<<"An Introduction to Database Systems">>, <<"C. J. Date">>),
book(<<"Less Than Words Can Say">>, <<"Richard Mitchell">>),
book(<<"The Graves of Academe">>, <<"Richard Mitchell">>),
book(<<"The Leaning Tower of Babel">>, <<"Richard Mitchell">>),
book(<<"The Gift of Fire">>, <<"Richard Mitchell">>)]).
book(Title, Author) -> {<<"book">>, #{<<"title">> => Title, <<"author">> => Author}}.
from(Books) ->
fun(Limit) ->
{Now, Later} = lists:split(min(Limit, length(Books)), Books),
{Now, case Later of [] -> done; _ -> from(Later) end}
end.