public function partitionBy($key) {
        $partition = array();
        foreach ($this->elements as $element) {
            $newEquivalenceClass = true;
            for ($i = 0; $i < count($partition); $i++) // partition[$i] is an equivalence class
                // an equivalence class is guaranteed to be non-empty
                if (call_user_func(array($element, $key), $partition[$i][0])) {
                    $partition[$i][] = $element;
                    $newEquivalenceClass = false;
                }
            if ($newEquivalenceClass)
                $partition[] = array($element);
        }
        return $partition;
    }