module Hamster::List
def group_by(&block)
def group_by(&block) return group_by { |item| item } unless block_given? reduce(EmptyHash) do |hash, item| key = yield(item) hash.put(key, (hash.get(key) || EmptyList).cons(item)) end end
def group_by(&block) return group_by { |item| item } unless block_given? reduce(EmptyHash) do |hash, item| key = yield(item) hash.put(key, (hash.get(key) || EmptyList).cons(item)) end end