Exemplo n.º 1
0
 /**
  * Creates a new set which contains the items that exist in the provided
  * set and do not exist in the current set.
  *
  * Formally:
  * B \ A = {x: x ∈ A ∧ x ∉ B}
  *
  * @param Set $that
  * @return Set
  */
 function complement(Set $that)
 {
     $complement = $this->cloneEmpty();
     if ($that === $this) {
         return $complement;
     }
     $this->addIf($complement, $that, negate([$this, 'has']));
     return $complement;
 }
Exemplo n.º 2
0
/**
 * @return \Closure
 */
function isNotEmpty()
{
    return negate(isEmpty());
}
Exemplo n.º 3
0
Arquivo: Fn.php Projeto: eschwartz/Fn
function odd()
{
    return negate(even());
}
Exemplo n.º 4
0
/**
 * @return \Closure
 */
function isNotMac()
{
    return negate(isMac());
}
Exemplo n.º 5
0
<?php

require "tests.php";
require "grouping.php";
check::functions(array("test1", "test2", "do_unary", "negate"));
check::equal(5, test1(5), "5==test1(5)");
check::resource(test2(7), "_p_int", "_p_int==test2(7)");
check::globals(array(test3));
//check::equal(37,test3_get(),'37==test3_get()');
check::equal(37, check::get("test3"), '37==get(test3)');
//test3_set(38);
check::set(test3, 38);
//check::equal(38,test3_get(),'38==test3_get() after test3_set(37)');
check::equal(38, check::get(test3), '38==get(test3) after set(test)');
check::equal(-5, negate(5), "-5==negate(5)");
check::equal(7, do_unary(-7, NEGATE), "7=do_unary(-7,NEGATE)");
check::done();
Exemplo n.º 6
0
/**
 * @param int $min
 * @param int $max
 * @return \Closure
 */
function notBetweenRight($min, $max)
{
    return negate(betweenRight($min, $max));
}
Exemplo n.º 7
0
/**
 * @param string $regex
 * @return \Closure
 */
function notMatch($regex)
{
    return negate(match($regex));
}
Exemplo n.º 8
0
/**
 * @param string $method
 * @param array  $methodArgs
 * @return \Closure
 */
function methodReturnNotEmpty($method, array $methodArgs = [])
{
    return negate(methodReturnEmpty($method, $methodArgs));
}
Exemplo n.º 9
0
/**
 * @param $end
 * @return \Closure
 */
function notEndWith($end)
{
    return negate(endWith($end));
}
Exemplo n.º 10
0
/**
 * @param array $values
 * @return \Closure
 */
function hasNotAnyOfValues(array $values)
{
    return negate(hasAnyOfValues($values));
}
Exemplo n.º 11
0
/**
 * Apply an inverse predicates map to a subject map.
 *
 * Takes a map of predicates and a subject in form of map, then apply to any item in the subject
 * the inverse of the predicate that has the same key in the predicate map.
 * The resulting array is composed by all the keys of subject set to `true` if the related predicate
 * returned `false` and `false` if the related predicate returned `true`.
 * All subject items without related predicate are `false` in the result.
 * Any item that is not callable in the predicate map is ignored.
 *
 * Example:
 *
 * <code>
 * <?php
 * use Pentothal as P;
 *
 * $predicates = [
 *   'name'  => P\combine(P\isString(), P\isNotEmpty()),
 *   'email' => P\isEmail(),
 *   'phone' => P\combine(P\isString(), P\startWith('+'), P\sizeMin(5)),
 * ];
 *
 * $user = [
 *   'name'  => 'John Doe',
 *   'email' => '*****@*****.**',
 *   'phone' => '---',
 * ];
 *
 * $errors = P\mapInverse($predicates, $user);
 *
 * var_export($errors); // array('name' => false, 'email' => false, 'phone' => true)
 * ?>
 * </code>
 *
 * @param array|object $predicateMap
 * @param array|object $subjectMap
 * @return bool[]
 * @throws \InvalidArgumentException If either `$predicateMap` or `$subjectMap` aren't objects or
 *                                   arrays
 */
function mapInverse($predicateMap, $subjectMap)
{
    /** @var array $predicates */
    $predicates = array_filter(mapAsArray($predicateMap), 'is_callable');
    /** @var array $subject */
    $subject = mapAsArray($subjectMap);
    $result = array_fill_keys(array_keys($subject), false);
    array_walk($predicates, function (callable $predicate, $key, $subject) use(&$result) {
        $negate = negate($predicate);
        isset($subject[$key]) and $result[$key] = $negate($subject[$key]);
    }, $subject);
    return $result;
}
Exemplo n.º 12
0
/**
 * @return \Closure
 */
function isNotArray()
{
    return negate(isArray());
}