/** * @test */ public function it_tests_array_some() { $numbers = [2, 4, 6, 7, 8, 10]; $evens = [2, 4, 6, 8, 10]; $this->assertTrue(array_some($numbers, function ($n) { return $n % 2 == 1; })); $this->assertFalse(array_some($evens, function ($n) { return $n % 2 == 1; })); }
/** * @param mixed $val * @return bool */ function is_array_list($val) { if (!is_array($val)) { $ret = false; } else { if (empty($val)) { $ret = true; // WARNING: common for both type of arrays } else { $ret = array_some($val, tuple_get(1, 'is_int')); } } return $ret; }
{ } abstract class AC2 extends AC1 { } abstract class AC3 extends AC2 implements Interf3 { } abstract class AC4 extends AC3 { } class C1 extends AC4 { } function array_some(array $array) { foreach ($array as $value) { if ($value) { echo "Empty: "; echo empty($value); echo "\nBool: "; echo $value ? "true" : "false"; echo "\n"; } } return "Done"; } $a = new C1(); var_dump(array_some(array_map(function ($v) { return $v instanceof Interf2; }, array($a))));
/** * @param callable,.. $callable * @return callable */ function or_dg($callable) { $functions = func_get_args(); return function () use($functions) { $args = func_get_args(); return array_some($functions, function ($function) use($args) { return call_user_func_array($function, $args); }); }; }
public function testIterator() { $this->assertTrue(array_some(new Range(1, 4), function ($value) { return $value % 2 === 0; })); }
/** * @param string|null $q * @param bool $collection * @return Lib_Model_Set * @throws Exception */ public function loadSet($q = null, $collection = false) { $q = $this->getSelect(); $pkey = $this->getPrimaryKey(); if (count($q->getPart('columns')) == 0) { $q->columns(['*']); } elseif (!$collection && !array_some($this->getColumns(), function ($arr) use($pkey) { return $pkey == zend_column_name($arr); })) { $this->setColumns($pkey); } $db = $this->getDb(); $this->preLoad(); try { $result = $db->fetchAll($q); } catch (Exception $e) { throw new Exception('Error while loading: ' . $e->getMessage() . ' | SQL: ' . $q->assemble()); } $this->postLoad(); $set = new Lib_Model_Set(); $set->setResultSet($result); $set->setModel($this); return $set; }
function is_assoc($xs) : bool { return \is_array($xs) && array_some('is_string', \array_keys($xs)); }
/** * @param null|Lib_Db_Mongo_Select $q * @param bool $collection * @return array * @fixme support for multiple result collections * @fixme $q needs relation with model */ public function loadArray($q = null, $collection = false) { $pkey = $this->getPrimaryKey(); if (!array_some($this->getColumns(), function ($arr) use($pkey) { return $arr[2] === $pkey; })) { $this->setColumns($pkey); } $data = array(); $select = null === $q ? $this->getSelect() : $q; $groups = $select->getGroups(); $initial = array("items" => array()); $reduce = "function (obj, prev) { prev.items.push(obj); }"; // if(!empty($groups)) // { // $cursor = $this->getCollection()->group($groups); // } // else // { $cursor = $this->getCollection()->find($select->getConditions(), $select->getFields()); // } if ($this->_timeout) { $cursor->timeout($this->_timeout); } if ($select->getOrder()) { $cursor->sort($select->getOrder()); } if ($select->getLimit()) { $cursor->limit($select->getLimit()); } $cursor->skip($select->getSkip()); foreach ($cursor as $row) { if (!$collection) { $id = (string) $row[$pkey]; $data[$id] = $row; } else { $data[] = $row; } } $alias = $this->getAlias(); return array($alias => $data); }
/** * @param string $backupFile * @param string $path * @return bool */ function tar_contains($backupFile, $path) { $output = tar_ls($backupFile); return array_some($output, function ($line) use($path) { return str_startswith($line, $path); }); }