logic.php
Tags
Table of Contents
Functions
- _and() : callable
- Function returns `true` if both arguments are `true`;
- both() : callable
- Function calling two provided functions and returning the `&&` of the results.
- either() : callable
- Function calling two provided functions and returning the `||` of the results.
- not() : callable
- Function returns inverted result of the input.
- neither() : callable
- Function calling two provided functions and returning true when both are returning false.
- _or() : callable
- Function returns `true` if at least one arguments is `true`;
Functions
_and()
Function returns `true` if both arguments are `true`;
_and(bool ...$v) : callable
Example:
_and(true, true); // it will return true
Parameters
- $v : bool
Tags
Return values
callable —both()
Function calling two provided functions and returning the `&&` of the results.
both(callable ...$v) : callable
This functions accepts two predicates and then return function accepting one parameter and calling both predicates
with that parameter. Then &&
of both results is returned.
Keep in mind that if first function will return false
second one won't be call.
Example:
both('is_number', below(3))(1) // it will return true
filter(both(above(18), below(30), [11, 19, 26, 40]); // it will return [19, 26]
Parameters
- $v : callable
Tags
Return values
callable —either()
Function calling two provided functions and returning the `||` of the results.
either(callable ...$v) : callable
This functions accepts two predicates and then return function accepting one parameter and calling both predicates
with that parameter. Then ||
of both results is returned.
Keep in mind that both given functions will be called.
Example:
either(above(5), below(3))(1) // it will return true
filter(either(above(18), below(30), [11, 19, 26, 40]); // it will return [11, 19, 26, 40]
Parameters
- $v : callable
Tags
Return values
callable —not()
Function returns inverted result of the input.
not(bool|callable $input) : callable
When callback is given it will return function that will run that callback and return inverted result. Note that this callback is supposed to return boolean.
Example:
not(true); // it will return false
not(false); // it will return true
not(above(5)); // it will return function accepting number and returning true if that number is not above 5
Parameters
- $input : bool|callable
Return values
callable —neither()
Function calling two provided functions and returning true when both are returning false.
neither(callable ...$v) : callable
This functions accepts two predicates and then return function accepting one parameter and calling both predicates
with that parameter. Then negation of &&
operation on both results is returned.
Keep in mind that if first function will return false
second one won't be call.
Example:
neither(above(5), below(3))(4) // it will return true
neither(above(1), below(3))(4) // it will return false
Parameters
- $v : callable
Tags
Return values
callable —_or()
Function returns `true` if at least one arguments is `true`;
_or(bool ...$v) : callable
Example:
_or(false, true); // it will return true
_or(false, false); // it will return false
Parameters
- $v : bool