<commit_before>/**
 * Created by elyde on 7/20/2017.
 */

import {curry, curry2} from './curry';

const

    pure = name => functor => functor[name](),

    pureOnOneTypeOneOrMore = name => curry2((functor, ...args) => functor[name](...args)),

    higherOrderOn2 = name => curry((fn, functor) => functor[name](fn)), // map, some, forEach etc.

    higherOrderOn3 = name => curry((fn, agg, functor) => functor[name](fn, agg)); // reduce, reduceRight

export const

    /**
     * Maps a function to functor (array etc.).
     * @function module:arrayOperators.map
     * @param fn {Function}
     * @param functor {Array|{map: {Function}}}
     * @returns {Array|{map: {Function}}}
     */
    map = higherOrderOn2('map'),

    /**
     * Filters a functor (array etc.) with passed in function.
     * @function module:arrayOperators.filter
     * @param fn {Function}
     * @param functor {Array|{filter: {Function}}}
     * @returns {Array|{filter: {Function}}}
     */
    filter = higherOrderOn2('filter'),

    /**
     * Reduces a foldable (array etc.) with passed in function.
     * @function module:arrayOperators.reduce
     * @param fn {Function}
     * @param functor {Array|{reduce: {Function}}}
     * @returns {Array|{reduce: {Function}}}
     */
    reduce = higherOrderOn2('reduce'),

    /**
     * Reduces a foldable (array etc.) from the right with passed in function.
     * @function module:arrayOperators.reduceRight
     * @param fn {Function}
     * @param functor {Array|{reduceRight: {Function}}}
     * @returns {Array|{reduceRight: {Function}}}
     */
    reduceRight = higherOrderOn3('reduceRight'),

    forEach = higherOrderOn2('forEach'),

    some = higherOrderOn2('some'),

    every = higherOrderOn2('every'),

    concat = pureOnOneTypeOneOrMore('concat');<commit_msg>prelude - progress on pure conversions of functor ops.<commit_after>/**
 * Created by elyde on 7/20/2017.
 * All functions here are functional versions of methods of types;  E.g., map, filter etc.
 */

import {curry, curry2} from './curry';

const

    fOpPure = name => functor => functor[name](),

    fOpPureOnOneOrMore = name => curry2((functor, ...args) => functor[name](...args)),

    fOpHigherOrderOn2 = name => curry((fn, functor) => functor[name](fn)), // map, some, forEach etc.

    fOpHigherOrderOn3 = name => curry((fn, agg, functor) => functor[name](fn, agg)); // reduce, reduceRight

export const

    /**
     * Maps a function to functor (array etc.).
     * @function module:arrayOperators.map
     * @param fn {Function}
     * @param functor {Array|{map: {Function}}}
     * @returns {Array|{map: {Function}}}
     */
    map = fOpHigherOrderOn2('map'),

    /**
     * Filters a functor (array etc.) with passed in function.
     * @function module:arrayOperators.filter
     * @param fn {Function}
     * @param functor {Array|{filter: {Function}}}
     * @returns {Array|{filter: {Function}}}
     */
    filter = fOpHigherOrderOn2('filter'),

    /**
     * Reduces a foldable (array etc.) with passed in function.
     * @function module:arrayOperators.reduce
     * @param fn {Function}
     * @param functor {Array|{reduce: {Function}}}
     * @returns {Array|{reduce: {Function}}}
     */
    reduce = fOpHigherOrderOn2('reduce'),

    /**
     * Reduces a foldable (array etc.) from the right with passed in function.
     * @function module:arrayOperators.reduceRight
     * @param fn {Function}
     * @param functor {Array|{reduceRight: {Function}}}
     * @returns {Array|{reduceRight: {Function}}}
     */
    reduceRight = fOpHigherOrderOn3('reduceRight'),

    /**
     * For each on functor (Array|Object|etc.).
     * @param fn {Function}
     * @param functor {Array|Object|*}
     * @return {*|Array|Object} - The type of object you pass in unless it doesn't have a `forEach` method.
     * @throws {Error} - When passed in functor doesn't have a `forEach` method.
     */
    forEach = fOpHigherOrderOn2('forEach'),

    /**
     * Returns `true` if `fn` (predicate) returns true for at least one item
     * in functor else returns `false`.
     * @param fn {Function} - Predicate.
     * @param functor {Array|Object|*}
     * @return {*|Array|Object} - The type passed.
     * @throws {Error} - When passed in object doesn't have a `some` method.
     */
    some = fOpHigherOrderOn2('some'),

    /**
     * Returns `true` if `fn` (predicate) returns true for all items in functor else returns `false`.
     * @param fn {Function} - Predicate.
     * @param functor {Array|Object|*}
     * @return {*|Array|Object} - The type passed.
     * @throws {Error} - When passed in object doesn't have an `every` method.
     */
    every = fOpHigherOrderOn2('every'),

    /**
     * Concats/appends all functors onto the end of first functor.
     * Note:  functors passed in after the first one must be of the same type.
     * @param functor {Array|Object|*}
     * @param ...functor {Array|Object|*}
     * @return {*|Array|Object} - The type passed.
     * @throws {Error} - When passed in object doesn't have an `every` method.
     */
    concat = fOpPureOnOneOrMore('concat');
{'fraction_non_alphanumeric': 0.15087719298245614, 'fraction_numerical': 0.007017543859649123, 'mean_word_length': 3.0054644808743167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4292763', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1544, 'n_words': 465}