Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Provides some idiomatic tools to help when programming using Erlang's Binary primitive type.
-module(my_binary).
-export([foreach/3]).
-export([fold/4]).
break(Blocksize, Bin) ->
<<Head:Blocksize/bits, Rest/bits>> = Bin,
{Head, Rest}.
foreach(_, _, <<>>) -> ok;
foreach(F, Blocksize, Bin) ->
{Head, Rest} = break(Blocksize, Bin),
F(Head),
foreach(F, Blocksize, Rest).
fold(_, Result, _, <<>>) -> Result;
fold(F, Initial, Blocksize, Bin) ->
{Head, Rest} = break(Blocksize, Bin),
Temp = F(Initial, Head),
fold(F, Temp, Blocksize, Rest).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.