Implements array_reduce, array_unique and ruby-like group_by functionality.