Skip to content

Instantly share code, notes, and snippets.

@jumski
jumski / piglet.rb
Last active February 18, 2016 11:34
Alternative implementation of codequest-eu/codequest_pipes :-)
class Trough < Array
alias_method :|, :push
def call(context)
reduce(context) do |ctx, pig|
pig.new(ctx).call
ctx
end
end
end
@michalmarczyk
michalmarczyk / merge-sorted.clj
Created May 1, 2012 03:28
Multiway merge of sorted sequences
(defn merge-sorted [comparator & xss]
(let [xss (into-array Object (remove empty? xss))
pq (java.util.PriorityQueue.
(count xss) #(comparator (val %1) (val %2)))]
(dotimes [i (count xss)]
(let [xs (aget xss i)]
(.add pq (pair i (first xs)))
(aset xss i (next xs))))
((fn go []
(lazy-seq