Пример #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;
}