Skip to content

Instantly share code, notes, and snippets.

@halfak
Created September 16, 2014 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halfak/dc73dff7a6667f867207 to your computer and use it in GitHub Desktop.
Save halfak/dc73dff7a6667f867207 to your computer and use it in GitHub Desktop.
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