Example #1
0
/**
 * f\rename_keys($coll, $keysMap)
 *
 * Returns a new coll with the keys from keysMap renamed.
 *
 * f\rename_keys(array('a' => 1, 'b' => 2), array('a' => 'c', 'b' => 'd'))
 * => array('c' => 1, 'd' => 2)
 */
function rename_keys($coll, $keysMap)
{
    if (f\not($keysMap)) {
        return $coll;
    }
    $from = f\first(f\keys($keysMap));
    $to = f\first($keysMap);
    return f\rename_keys(f\rename_key($coll, $from, $to), f\dissoc($keysMap, $from));
}
 private function filterParamsToDomain($params)
 {
     return f\rename_key($params, 'oauth2Id', 'id');
 }
Example #3
0
 /**
  * @dataProvider renameKeyProvider
  */
 public function testRenameKey($coll)
 {
     $this->assertSame(array('foo' => 3, 'ups' => 9), f\rename_key($coll, 'bar', 'ups'));
     $this->assertSame(f\to_array($coll), f\rename_key($coll, 'bar', 'bar'));
 }