Created
September 16, 2014 18:36
-
-
Save halfak/dc73dff7a6667f867207 to your computer and use it in GitHub Desktop.
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
function consume_chunk(vector, split, start=1){ | |
items = c() | |
location = start | |
for(item in vector[start:length(vector)]){ | |
items = c(items, item) | |
location += 1 | |
if(split(item)){ | |
break | |
} | |
} | |
list(end=location, items=items) | |
} | |
function aggregate(vector, split, func){ | |
results = c() | |
start = 1 | |
while(start <= length(vector)){ | |
chunk = consume_chunk(vector, split, start) | |
results = c(results, func(chunk$items)) | |
start = chunk$location | |
} | |
results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment