Skip to content

Commit

Permalink
Moved a demo up to the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Jun 26, 2018
1 parent 6ec88f6 commit 30cff7c
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,6 @@ Pipeline comes with the most important yet basic building blocks. It boasts meth

This rigorously tested library just works. Pipeline never throws any exceptions.

# Entry points

All entry points always return an instance of a standard pipeline.

| Method | Details |
| ----------- | ----------------------------- |
| `map()` | Takes an optional initial callback, where it must not require any arguments. Other than that, works just like an instance method below. |
| `take()` | Takes any Traversable, initializes a standard pipeline with it. |
| `fromArray()` | Takes an array, initializes a standard pipeline with it. |

# Instance methods in a nutshell

| Method | Details | A.K.A. |
| ----------- | ----------------------------- | ----------------- |
| `map()` | Takes an optional callback that for each input value may return one or yield many. Also takes an initial generator, where it must not require any arguments. Provided no callback does nothing. Also available as a plain function. | `array_map`, `Select`, `SelectMany` |
| `unpack()` | Unpacks arrays into arguments for a callback. Flattens inputs if no callback provided. | `flat_map`, `flatten` |
| `filter()` | Removes elements unless a callback returns true. Removes falsey values if no callback provided. | `array_filter`, `Where` |
| `reduce()` | Reduces input values to a single value. Defaults to summation. | `array_reduce`, `Aggregate`, `Sum` |
| `toArray()` | Returns an array with all values. Eagerly executed. | `dict`, `ToDictionary` |
| `__construct()` | Can be provided with an optional initial iterator. Used in the `take()` function from above. Not part of any interface. | |

Pipeline is an iterator and can be used as any other iterable. Implements `JsonSerializable`.

Pipeline is a final class. It comes with a pair of interfaces to aid you with [composition over inheritance](https://stackoverflow.com/questions/30683432/inheritance-over-composition).

# Install

Expand Down Expand Up @@ -94,6 +70,31 @@ var_dump($value);
// int(104)
```

# API entry points

All entry points always return an instance of a standard pipeline.

| Method | Details | Use with |
| ----------- | ----------------------------- | ----------- |
| `map()` | Takes an optional initial callback, where it must not require any arguments. Other than that, works just like an instance method below. | `use function Pipeline\map;` |
| `take()` | Takes any Traversable, initializes a standard pipeline with it. | `use function Pipeline\take;` |
| `fromArray()` | Takes an array, initializes a standard pipeline with it. | `use function Pipeline\fromArray;` |

# Instance methods in a nutshell

| Method | Details | A.K.A. |
| ----------- | ----------------------------- | ----------------- |
| `map()` | Takes an optional callback that for each input value may return one or yield many. Also takes an initial generator, where it must not require any arguments. Provided no callback does nothing. Also available as a plain function. | `array_map`, `Select`, `SelectMany` |
| `unpack()` | Unpacks arrays into arguments for a callback. Flattens inputs if no callback provided. | `flat_map`, `flatten` |
| `filter()` | Removes elements unless a callback returns true. Removes falsey values if no callback provided. | `array_filter`, `Where` |
| `reduce()` | Reduces input values to a single value. Defaults to summation. | `array_reduce`, `Aggregate`, `Sum` |
| `toArray()` | Returns an array with all values. Eagerly executed. | `dict`, `ToDictionary` |
| `__construct()` | Can be provided with an optional initial iterator. Used in the `take()` function from above. Not part of any interface. | |

Pipeline is an iterator and can be used as any other iterable. Implements `JsonSerializable`.

Pipeline is a final class. It comes with a pair of interfaces to aid you with [composition over inheritance](https://stackoverflow.com/questions/30683432/inheritance-over-composition).

# Caveats

- Since most callback are [lazily evaluated](https://en.wikipedia.org/wiki/Lazy_evaluation) as more data coming in and out, you must consume the results with a plain `foreach` or use a `reduce()` to make sure processing happens.
Expand Down

0 comments on commit 30cff7c

Please sign in to comment.