<commit_before><?php
/**
 * Created by PhpStorm.
 * User: jasondent
 * Date: 12/03/15
 * Time: 16:34
 */

class FnGen {
    /**
     * @return callable
     */
    public static function fnKeepNotEmpty() {
        return function ($v) { return !empty($v); };
    }

    /**
     * @return callable
     */
    public static function fnKeepIsSet() {
        return function ($v) { return isset($v); };
    }

    /**
     * Alias for fnKeepIsSet
     *
     * Usage Sequence::make($values)->filter(FnGen::clean())->to_a();
     *
     * @return callable
     */
    public static function fnClean() {
        return static::fnKeepIsSet();
    }


    /**
     * Generates a function that returns true if $map has a key that matches the value.
     *
     * @param array|ArrayAccess $map
     * @return callable
     */
    public static function fnKeepInMap($map) {
        if (is_array($map)) {
            return function ($v) use ($map) { return array_key_exists($v, $map);};
        } else if (class_implements($map, 'ArrayAccess')) {
            return function ($v) use($map) { return $map->offsetExists($v); };
        }
        // just use isset
        return function ($v) use($map) { return isset($map[$v]); };
    }

    /**
     * Generates a function that returns false if $map has a key that matches the value.
     *
     * @param array|ArrayAccess $map
     * @return callable
     */
    public static function fnKeepNotInMap($map) {
        $fnInMap = static::fnKeepInMap($map);
        return function ($v) use($fnInMap) { return ! $fnInMap($v); };
    }

    /**
     * Generates a function that returns true if a value is equal
     *
     * @param $value
     * @return callable
     */
    public static function fnIsEqual($value) {
        return function ($v) use($value) { return $value == $v; };
    }


    /**
     * Generates a function that returns true if a value is not equal
     *
     * @param $value
     * @return callable
     */
    public static function fnIsNotEqual($value) {
        return function ($v) use($value) { return $value != $v; };
    }


    /**
     * @param $array
     * @return callable
     */
    public static function fnKeepInArray($array) {
        return function ($v) use($array) { return in_array($v, $array);};
    }

    /**
     * Generate a function that returns true if an object implements an interface
     *
     * @param $className
     * @return callable
     */
    public static function fnKeepImplements($className) {
        return function ($v) use ($className) { return class_implements($v, $className); };<commit_msg>REV-9949 fix constants to the new values.<commit_after><?php
/**
 * Created by PhpStorm.
 * User: jasondent
 * Date: 12/03/15
 * Time: 16:34
 */

class FnGen {
    /**
     * @return callable
     */
    public static function fnKeepNotEmpty() {
        return function ($v) { return !empty($v); };
    }

    /**
     * @return callable
     */
    public static function fnKeepIsSet() {
        return function ($v) { return isset($v); };
    }

    /**
     * Alias for fnKeepIsSet
     *
     * Usage Sequence::make($values)->filter(FnGen::clean())->to_a();
     *
     * @return callable
     */
    public static function fnClean() {
        return static::fnKeepIsSet();
    }


    /**
     * Generates a function that returns true if $map has a key that matches the value.
     *
     * @param array|ArrayAccess $map
     * @return callable
     */
    public static function fnKeepInMap($map) {
        if (is_array($map)) {
            return function ($v) use ($map) { return array_key_exists($v, $map);};
        } else if (class_implements($map, 'ArrayAccess')) {
            return function ($v) use($map) { return $map->offsetExists($v); };
        }
        // just use isset
        return function ($v) use($map) { return isset($map[$v]); };
    }

    /**
     * Generates a function that returns false if $map has a key that matches the value.
     *
     * @param array|ArrayAccess $map
     * @return callable
     */
    public static function fnKeepNotInMap($map) {
        $fnInMap = static::fnKeepInMap($map);
        return function ($v) use($fnInMap) { return ! $fnInMap($v); };
    }

    /**
     * Generates a function that returns true if a value is equal
     *
     * @param $value
     * @return callable
     */
    public static function fnIsEqual($value) {
        return function ($v) use($value) { return $value == $v; };
    }

    /**
     * Generates a function that returns true if a value is numeric
     *
     * @return callable
     */
    public static function fnIsNumeric() {
        return function ($v) { return is_numeric($v); };
    }

    /**
     * Generates a function that returns true if a value is not equal
     *
     * @param $value
     * @return callable
     */
    public static function fnIsNotEqual($value) {
        return function ($v) use($value) { return $value != $v; };
    }


    /**
     * @param $array
     * @return callable
     */
    public static function fnKeepInArray($array) {
        return function ($v) use($array) { return in_array($v, $array);};
    }

    /**
     * Generate a function that returns true if an object implements an interface
     *
     * @param $className
     * @return callable
     */
    public static function fnKeepImplements($className) {
        return function ($v) use ($className) { return class_implements($v, $className); };
{'fraction_non_alphanumeric': 0.13478818998716302, 'fraction_numerical': 0.004401247019988997, 'mean_word_length': 2.2348754448398576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2779625', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1609, 'n_words': 484}