FeaturePhp/Helper/Partition.php
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;
    }
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;
    }
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 ; }
Partitions the elements using an equivalence relation.
@param callable $key a binary relation on the elements
@return array[]
Partitions the elements using an equivalence relation .