<commit_before># Underscore

[![Build Status](https://travis-ci.org/Im0rtality/Underscore.png?branch=master)](https://travis-ci.org/Im0rtality/Underscore)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/Im0rtality/Underscore/badges/quality-score.png?s=a360715f49ea4bba225b7991146981ca80b61337)](https://scrutinizer-ci.com/g/Im0rtality/Underscore/)
[![Code Coverage](https://scrutinizer-ci.com/g/Im0rtality/Underscore/badges/coverage.png?s=e9c5669f300b4d8cb96d0fa8645119ab546fbd62)](https://scrutinizer-ci.com/g/Im0rtality/Underscore/)

Functional programming library for PHP

# Code example
```php
    Underscore::from([1,2,3,4,5])
            // convert array format
        ->map(function($num) { return ['number' => $num]];})
            // filter out odd elements
        ->filter(function($item) { return $item['num'] % 2;})
            // vardump elements
        ->each('vardump')
            // changed my mind, I only want numbers
        ->pluck('number')
            // add numbers to 1000
        ->reduce(function($sum, $num) { $sum += $num; return $sum; }, 1000)
            // take result
        ->value();
            // should be 1006
```
# Motivation
Originaly I needed functional programming magic for other project, so had to pick one lib or write my own.

There is several PHP ports of UnderscoreJS, however none of those fit my requirements (nice code, easy to write, standardized):
 - [brianhaveri/Underscore.php](https://github.com/brianhaveri/Underscore.php) - not maintained, messy code
 - [Anahkiasen/underscore-php](https://github.com/Anahkiasen/underscore-php) - Laravel4 package => incompatible with PSR-2

# Installation
Via composer:

    $ composer require Im0rtality/Underscore:dev-master

Composer docs recommend to use specific version. You can look them up in [Releases](https://github.com/Im0rtality/Underscore/releases).

# API Reference

- toArray
- each
- map
- reduce
- reduceRight
- pluck
- contains

## TODO
- invoke
- any
- all
- filter
- reject
- find
- size
- head
- tail
- initial
- last
- compact
- flatten
- without
- uniq
- intersection
- union
- difference
- indexOf
- lastIndexOf
- range
- zip
- max
- min
- sortBy
- groupBy
- sortedIndex
- shuffle
- keys
- values
- extend
- defaults
- methods
- clone
- tap
- has
- isEqual
- isEmpty
- isObject
- isArray
- isString
- isNumber
- isBoolean
- isFunction
- isDate
- isNaN
- identity
- uniqueId
- times
- mixin
- memoize
- throttle
- once
- wrap
- compose
- after

# Tests<commit_msg>Moved TODO list to issue instead of README<commit_after># Underscore

[![Build Status](https://travis-ci.org/Im0rtality/Underscore.png?branch=master)](https://travis-ci.org/Im0rtality/Underscore)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/Im0rtality/Underscore/badges/quality-score.png?s=a360715f49ea4bba225b7991146981ca80b61337)](https://scrutinizer-ci.com/g/Im0rtality/Underscore/)
[![Code Coverage](https://scrutinizer-ci.com/g/Im0rtality/Underscore/badges/coverage.png?s=e9c5669f300b4d8cb96d0fa8645119ab546fbd62)](https://scrutinizer-ci.com/g/Im0rtality/Underscore/)

Functional programming library for PHP

# Code example
```php
    Underscore::from([1,2,3,4,5])
            // convert array format
        ->map(function($num) { return ['number' => $num]];})
            // filter out odd elements
        ->filter(function($item) { return $item['num'] % 2;})
            // vardump elements
        ->each('vardump')
            // changed my mind, I only want numbers
        ->pluck('number')
            // add numbers to 1000
        ->reduce(function($sum, $num) { $sum += $num; return $sum; }, 1000)
            // take result
        ->value();
            // should be 1006
```
# Motivation
Originaly I needed functional programming magic for other project, so had to pick one lib or write my own.

There is several PHP ports of UnderscoreJS, however none of those fit my requirements (nice code, easy to write, standardized):
 - [brianhaveri/Underscore.php](https://github.com/brianhaveri/Underscore.php) - not maintained, messy code
 - [Anahkiasen/underscore-php](https://github.com/Anahkiasen/underscore-php) - Laravel4 package => incompatible with PSR-2

# Installation
Via composer:

    $ composer require Im0rtality/Underscore:dev-master

Composer docs recommend to use specific version. You can look them up in [Releases](https://github.com/Im0rtality/Underscore/releases).

# API Reference

- toArray
- each
- map
- reduce
- reduceRight
- pluck
- contains

## TODO

Check open [issues](https://github.com/Im0rtality/Underscore/issues)

# Tests
{'fraction_non_alphanumeric': 0.13168814151561475, 'fraction_numerical': 0.03603406857392444, 'mean_word_length': 3.312617702448211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 19, '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': '6356389', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1522, 'n_words': 351}