Created
April 2, 2011 06:55
-
-
Save alexbowe/899298 to your computer and use it in GitHub Desktop.
Provides some idiomatic tools to help when programming using Erlang's Binary primitive type.
This file contains 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
-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