pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/bertptrs/phpstreams

mous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-0b53c3bf3393e2ed.css" /> GitHub - bertptrs/phpstreams: A streams library for PHP inspired by the Java 8 Streams API.
Skip to content

A streams library for PHP inspired by the Java 8 Streams API.

License

Notifications You must be signed in to change notification settings

bertptrs/phpstreams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPStreams

Latest Stable Version Total Downloads License Build Status

A partial implementation of the Java 8 Streams API in PHP. PHPStreams can use your generators, your arrays and really anything that is Iterable and convert modify it like you're used to using Java Streams!

Using streams and generators, you can easily sort through large amounts of data without having to have it all in memory or in scope. Streams also make it easier to structure your code, by (more or less) enforcing single resposibility.

The library is compatible with PHP 5.5.9 and up.

Installation

PHPStreams can be installed using Composer. Just run composer require bertptrs/phpstreams in your project root!

Usage

Using streams is easy. Say, we want the first 7 odd numbers in the Fibonacci sequence. To do this using Streams, we do the following:

// Define a generator for Fibonacci numbers
function fibonacci()
{
    yield 0;
    yield 1;

    $prev = 0;
    $cur = 1;

    while (true) {
        yield ($new = $cur + $prev);
        $prev = $cur;
        $cur = $new;
    }
};

// Define a predicate that checks for odd numbers
$isOdd = function($num) {
    return $num % 2 == 1;
};

// Create our stream.
$stream = new phpstreams\Stream(fibonacci());

// Finally, use these to create our result.
$oddFibo = $stream->filter($isOdd)  // Keep only the odd numbers
    ->limit(8)                      // Limit our results
    ->toArray(false);               // Convert to array, discarding keys

Documentation

Documentation is mostly done using PHPDoc. I do intend to write actual documtation if there is any interest.

Contributing

I welcome contributions and pull requests. Please note that I do follow PSR-2 (and PSR-4 for autoloading). Also, please submit unit tests with your work.

GrumPHP enforces at least part of the coding standard, but do make an effort to structure your contributions nicely.

About

A streams library for PHP inspired by the Java 8 Streams API.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy