Skip to content

Commit

Permalink
Require PHP 5.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrovich committed Feb 23, 2020
1 parent 60b88a7 commit cc46eb0
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 231 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ language: php
dist: xenial

php:
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
Expand Down
90 changes: 42 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Dash   [![Latest Stable Version](https://poser.pugx.org/mpetrovich/dash/version)](https://packagist.org/packages/mpetrovich/dash) [![Build Status](https://travis-ci.org/mpetrovich/dash.svg?branch=master)](https://travis-ci.org/mpetrovich/dash) [![codecov](https://codecov.io/gh/mpetrovich/dash/branch/master/graph/badge.svg)](https://codecov.io/gh/mpetrovich/dash)
===
# Dash   [![Latest Stable Version](https://poser.pugx.org/mpetrovich/dash/version)](https://packagist.org/packages/mpetrovich/dash) [![Build Status](https://travis-ci.org/mpetrovich/dash.svg?branch=master)](https://travis-ci.org/mpetrovich/dash) [![codecov](https://codecov.io/gh/mpetrovich/dash/branch/master/graph/badge.svg)](https://codecov.io/gh/mpetrovich/dash)

**A functional programming library for PHP.** Inspired by Underscore, Lodash, and Ramda.

```php
Expand All @@ -19,6 +19,7 @@ echo "Average male age is $avgMaleAge.";
```

#### Operations - [View all](docs/Operations.md)

[all / every](docs/Operations.md#all--every),
[any / some](docs/Operations.md#any--some),
[apply](docs/Operations.md#apply),
Expand Down Expand Up @@ -103,34 +104,26 @@ echo "Average male age is $avgMaleAge.";
[values](docs/Operations.md#values)

#### Jump to:
- [Highlights](#highlights)
- [Why use Dash?](#why-use-dash)
- [Installation](#installation)
- [Usage](#usage)
- [Standalone](#standalone)
- [Chaining](#chaining)
- [Supported data types](#supported-data-types)
- [Currying](#currying)
- [Lazy evaluation](#lazy-evaluation)
- [Custom operations](#custom-operations)
- [Tips](#tips)
- [Changelog](https://github.com/mpetrovich/dash/releases)
- [Roadmap](docs/Roadmap.md)
- [Contributing](CONTRIBUTING.md)


Highlights
---
- [Many data types supported](#supported-data-types): arrays, objects, generators ([coming soon](https://github.com/mpetrovich/dash/issues/3)), [`Traversable`](http://php.net/manual/en/class.traversable.php), [`DirectoryIterator`](http://php.net/manual/en/class.directoryiterator.php), and more
- [Chaining](#chaining)
- [Currying](#currying)
- [Lazy evaluation](#lazy-evaluation)
- [Custom operations](#custom-operations)
- Well-tested: Comprehensive tests with nearly 3,000 test cases and [100% code coverage](https://codecov.io/gh/mpetrovich/dash)


Why use Dash?
---

- [Highlights](#highlights)
- [Why use Dash?](#why-use-dash)
- [Installation](#installation)
- [Usage](#usage) - [Standalone](#standalone) - [Chaining](#chaining) - [Supported data types](#supported-data-types) - [Currying](#currying) - [Lazy evaluation](#lazy-evaluation) - [Custom operations](#custom-operations) - [Tips](#tips)
- [Changelog](https://github.com/mpetrovich/dash/releases)
- [Roadmap](docs/Roadmap.md)
- [Contributing](CONTRIBUTING.md)

## Highlights

- [Many data types supported](#supported-data-types): arrays, objects, generators ([coming soon](https://github.com/mpetrovich/dash/issues/3)), [`Traversable`](http://php.net/manual/en/class.traversable.php), [`DirectoryIterator`](http://php.net/manual/en/class.directoryiterator.php), and more
- [Chaining](#chaining)
- [Currying](#currying)
- [Lazy evaluation](#lazy-evaluation)
- [Custom operations](#custom-operations)
- Well-tested: Comprehensive tests with nearly 3,000 test cases and [100% code coverage](https://codecov.io/gh/mpetrovich/dash)

## Why use Dash?

PHP's built-in `array_*` functions are limited, difficult to compose, inconsistent, and don't work across many data types.

For instance, let's say we want to find the average age of males in this list:
Expand Down Expand Up @@ -166,21 +159,20 @@ $avgMaleAge = Dash\chain($people)

This is just a tiny subset of what Dash can do. [**See the full list of operations here.**](docs/Operations.md)

## Installation

Requires PHP 5.6+

Installation
---
Requires PHP 5.4+
```sh
composer require mpetrovich/dash
```

## Usage

Usage
---
Dash operations are pure functions that can be used alone or chained together.


### Standalone

Operations can be called as namespaced functions:

```php
Expand All @@ -203,8 +195,8 @@ use Dash\_;
_::map([1, 2, 3], function ($n) { return $n * 2; }); // === [2, 4, 6]
```


### Chaining

Multiple operations can be chained in sequence using `chain()`. Call `value()` to return the final value.

```php
Expand Down Expand Up @@ -264,16 +256,18 @@ $chain->run();
// T-minus 1...
```


### Supported data types

Dash can work with a wide variety of data types, including:
- arrays
- objects (eg. `stdClass`)
- generators ([coming soon](https://github.com/mpetrovich/dash/issues/3))
- anything that implements the [`Traversable`](http://php.net/manual/en/class.traversable.php) interface
- [`DirectoryIterator`](http://php.net/manual/en/class.directoryiterator.php), which is also a `Traversable` but cannot normally be used with `iterator_to_array()` [due to a PHP bug](https://bugs.php.net/bug.php?id=49755). Dash works around this transparently.

- arrays
- objects (eg. `stdClass`)
- generators ([coming soon](https://github.com/mpetrovich/dash/issues/3))
- anything that implements the [`Traversable`](http://php.net/manual/en/class.traversable.php) interface
- [`DirectoryIterator`](http://php.net/manual/en/class.directoryiterator.php), which is also a `Traversable` but cannot normally be used with `iterator_to_array()` [due to a PHP bug](https://bugs.php.net/bug.php?id=49755). Dash works around this transparently.

#### Examples

With an array:

```php
Expand Down Expand Up @@ -323,8 +317,8 @@ $filenames = Dash\chain($iterator)
->value();
```


### Currying

[`curry()`](docs/Operations.md#curry) and related operations can be used to create curried functions from any callable:

```php
Expand Down Expand Up @@ -365,8 +359,8 @@ $sayHello('Mark'); // === 'Hello, Mark!'
$sayHowdy('Jane'); // === 'Howdy, Jane!'
```


### Lazy evaluation

Chained operations are not evaluated until `value()` or `run()` is called. Furthermore, the input data can be changed and evaluated multiple times using `with()`. This makes it simple to create reusable chains:

```php
Expand All @@ -392,8 +386,8 @@ $chain->value(); // === [10, 14]

When `value()` is called, the result is cached until the chain is modified or the input is changed using `with()`.


### Custom operations

Custom operations can be added, retrieved, and removed using `setCustom()`, `getCustom()`, and `unsetCustom()`, respectively. `Dash\custom()` is also an alias for `Dash::getCustom()`:

```php
Expand Down Expand Up @@ -426,8 +420,8 @@ Dash\chain([1, 2, 3])
Dash::unsetCustom('triple');
```


### Tips

If you find that Dash doesn't have an operation that you need, fear not. Custom logic can be added without giving up Dash chaining or other features. The simplest way to integrate missing operations is via the [`Dash\thru()`](docs/Operations.md#thru) operation, which allows custom logic to modify and seamlessly pass through its results to the next step in the chain.

For example, suppose we want to use `array_change_key_case()` and keep the usual Dash chaining semantics. With `thru()`, it's simple:
Expand Down Expand Up @@ -464,6 +458,6 @@ $result = Dash\chain(['one' => 1, 'two' => 2, 'three' => 3])
// $result === ['ONE', 'THREE']
```


### Feedback

Found a bug or have a suggestion? Please [create a new GitHub issue](https://github.com/mpetrovich/dash/issues/new). We want your feedback!

0 comments on commit cc46eb0

Please sign in to comment.