示例#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));
}
示例#2
0
 /**
  * @dataProvider provideEmptyColl
  */
 public function testEmptyCollection($collection)
 {
     $this->assertSame(array(), f\keys($collection));
 }
示例#3
0
 /**
  * @Given /^there is a user "([^"]*)" with password "([^"]*)"$/
  */
 public function thereIsAUserWithPassword($username, $password)
 {
     $this->users[] = ['id' => count($this->users) ? f\last(f\keys($this->users)) : 1, 'username' => $username, 'password' => $password];
 }
示例#4
0
/**
 * f\drop_last($coll)
 *
 * Returns an array based on coll with the last element removed.
 *
 * f\drop_last(array('a' => 1, 'b' => 2));
 * => array('a' => 1)
 */
function drop_last($coll)
{
    $result = f\to_array($coll);
    unset($result[f\last(f\keys($result))]);
    return $result;
}