Category talk:Wren-seq: Difference between revisions

Content added Content deleted
(→‎Source code: Bug fix.)
(→‎Source code: Added Lst.groupBy method.)
Line 202: Line 202:
}
}
return g
return g
}

// Applies a function to each element of a list to produce a key and returns a map of each
// distinct key to a list of the corresponding elements. The latter retain their original
// order within the list and the key must be a value type.
static groupBy(a, fn) {
isList_(a)
var m = {}
for (e in a) {
var k = fn.call(e)
if (!m.containsKey(k)) {
m[k] = [e]
} else {
m[k].add(e)
}
}
return m
}
}