Slice chunking in Go

You don’t need to make new slices, just append slices of logs to the divided slice. http://play.golang.org/p/vyihJZlDVy var divided [][]string chunkSize := (len(logs) + numCPU – 1) / numCPU for i := 0; i < len(logs); i += chunkSize { end := i + chunkSize if end > len(logs) { end = len(logs) } divided … Read more

How do I avoid Clojure’s chunking behavior for lazy seqs that I want to short circuit?

CORRECTED TWICE: A simpler way to un-chunk a lazy sequence: (defn unchunk [s] (when (seq s) (lazy-seq (cons (first s) (unchunk (next s)))))) First version omitted (when … so it returned an infinite seq of nil’s after the input sequence ended. Second version used first instead of seq so it stopped on nil. RE: your … Read more