Skip to content

Commit

Permalink
pull out anonymous functions in groupByKey
Browse files Browse the repository at this point in the history
  • Loading branch information
lythesia committed Feb 8, 2015
1 parent ba6f044 commit f5038c0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/R/RDD.R
Original file line number Diff line number Diff line change
Expand Up @@ -1383,20 +1383,21 @@ setMethod("groupByKey",
vals <- new.env()
keys <- new.env()
pred <- function(item) exists(item$hash, keys)
appendList <- function(acc, x) {
addItemToAccumulator(acc, x)
acc
}
makeList <- function(x) {
acc <- initAccumulator()
addItemToAccumulator(acc, x)
acc
}
# Each item in the partition is list of (K, V)
lapply(part,
function(item) {
item$hash <- as.character(hashCode(item[[1]]))
updateOrCreatePair(item, keys, vals, pred,
function(acc, x) {
addItemToAccumulator(acc, x)
acc
},
function(x) {
acc <- initAccumulator()
addItemToAccumulator(acc, x)
acc
})
appendList, makeList)
})
# extract out data field
vals <- eapply(vals,
Expand Down

0 comments on commit f5038c0

Please sign in to comment.