[erlang-questions] gb_trees:fold?

James Hague james.hague@REDACTED
Mon May 24 18:03:05 CEST 2010


Okay, here's gb_trees:fold/3:

-spec fold(fun((term(), term(), term()) -> term()), term(), gb_tree()) ->
term().

fold(F, A, {_, T}) when is_function(F, 3) ->
    fold_1(F, A, T).

fold_1(F, Acc0, {Key, Value, Small, Big}) ->
    Acc1 = fold_1(F, Acc0, Small),
    Acc = F(Key, Value, Acc1),
    fold_1(F, Acc, Big);
fold_1(_, Acc, _) ->
    Acc.

Yes, I should submit this to git and add an entry to the docs, but that will
have to wait for more time on my part. It was fun to discover how easy this
was to write, regardless!


More information about the erlang-questions mailing list