public function testOptionHelpers() { $this->assertInstanceOf(Option\Some::class, some($this->initialValue)); $this->assertInstanceOf(Option\None::class, none()); $this->assertInstanceOf(Option\Some::class, wrap($this->initialValue, $this->alternativeValue)); $this->assertInstanceOf(Option\None::class, wrap($this->initialValue, $this->initialValue)); }
/** * @param $value * @param callable $callback * * @return Optional */ function maybe($value, callable $callback = null) : Optional { $callback = $callback ?? 'Dgame\\Optional\\verify'; if ($callback($value)) { return some($value); } return none(); }
/** * Like some(), with 1 as count. However, if the promise fulfills, the * fulfillment value is not an array of 1 but the value directly. * * @param mixed $promises Promises or values. * * @return PromiseInterface */ function any($promises) { return some(1, $promises)->then(function ($values) { return $values[0]; }); }
echo 'OK<br>'; } else { echo 'erro<br>'; } if (multi(5, 2) == 5 * 2) { echo 'OK<br>'; } else { echo 'erro<br>'; } if (divide(5, 2) == 5 / 2) { echo 'OK<br>'; } else { echo 'erro<br>'; } if (some(5, multi(2, 3)) == 5 + 2 * 3) { echo 'OK<br>'; } else { echo 'erro<br>'; } if (subtrair(8, some(3, 5)) == 8 - (3 + 5)) { echo 'OK<br>'; } else { echo 'erro<br>'; } if (some(divide(9, 3), multi(4, 2)) == 9 / 3 + 4 * 2) { echo 'OK<br>'; } else { echo 'erro<br>'; } ?> </pre>
public function __toString() { some(); }
function any($promisesOrValues) { return some($promisesOrValues, 1)->then(function ($val) { return array_shift($val); }); }
/** * Returns false if $callback($x) is logical true for any $x in $arr, else true. */ function not_any($callback, array $arr) { return !some($callback, $arr); }
/** @test */ public function shouldResolveToEmptyArrayWhenInputPromiseDoesNotResolveToArray() { $mock = $this->createCallableMock(); $mock->expects($this->once())->method('__invoke')->with($this->identicalTo([])); some(resolve(1), 1)->then($mock); }
<td width='25%'><b><?php echo $accno; ?> </b></td> <td width='25%'><b><?php echo $gender; ?> </b></td> <td width="15%" valign=top><center><a href="view_profile.php?accno=<?php echo $accno; ?> " class="btn btn-mini btn-warning"><strong>View Profile</strong></a></center></td> </tr> <?php $m++; some(); } } } else { if ($opt == "Accno") { if (strlen(trim($content)) == 0 or strlen(trim($content)) != 7) { echo "<script>show_info('Messg : Search Content should not be null');</script>"; exit; } $q1 = mysql_query("SELECT * FROM b1_users WHERE accno LIKE '%{$content}%' "); $q0 = mysql_fetch_array($q1); if (empty($q0)) { echo "<script>show_info('Messg : No Results Found');</script>"; exit; } else { header("Location:view_profile.php?accno={$content}");
<?php require_once __DIR__ . '/../../vendor/autoload.php'; use function jubianchi\async\runtime\{await, some}; function producer($prefix, $length) : \generator { $cancel = false; for ($i = 0; $i < $length && $cancel === false; $i++) { echo $prefix . '-' . $i . PHP_EOL; $cancel = (bool) yield; } if ($cancel === true) { echo $prefix . '-canceled' . PHP_EOL; } return $prefix . '-' . __LINE__; } var_dump(await(some(2, producer(__LINE__, 5), producer(__LINE__, 10), producer(__LINE__, 2))));
public function some($callback) { return some($this, $callback); }
/** @test */ public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills() { $mock = $this->createCallableMock(); $mock->expects($this->never())->method('__invoke'); $deferred = new Deferred($mock); $deferred->resolve(); $mock2 = $this->getMock('React\\Promise\\CancellablePromiseInterface'); $mock2->expects($this->once())->method('cancel'); some([$deferred->promise(), $mock2], 1)->cancel(); }