https://github.com/munusphp/munus
  
  
    Power of object-oriented programming with the elegance of functional programming in PHP. 
    https://github.com/munusphp/munus
  
functional-programming hacktoberfest immutable-collections immutable-objects object-functional php stream
        Last synced: 4 months ago 
        JSON representation
    
Power of object-oriented programming with the elegance of functional programming in PHP.
- Host: GitHub
 - URL: https://github.com/munusphp/munus
 - Owner: munusphp
 - License: mit
 - Created: 2019-10-24T17:01:26.000Z (about 6 years ago)
 - Default Branch: master
 - Last Pushed: 2024-05-29T07:58:11.000Z (over 1 year ago)
 - Last Synced: 2024-05-29T20:36:30.733Z (over 1 year ago)
 - Topics: functional-programming, hacktoberfest, immutable-collections, immutable-objects, object-functional, php, stream
 - Language: PHP
 - Homepage: https://munusphp.github.io/
 - Size: 502 KB
 - Stars: 171
 - Watchers: 11
 - Forks: 12
 - Open Issues: 6
 - 
            Metadata Files:
            
- Readme: README.md
 - Contributing: CONTRIBUTING.md
 - License: LICENSE
 
 
Awesome Lists containing this project
README
          # Munus
[](https://php.net/)
[](https://github.com/munusphp/munus/actions?query=workflow%3Abuild)
[](https://packagist.org/packages/munusphp/munus)
[](https://codecov.io/gh/munusphp/munus)
[](https://packagist.org/packages/munusphp/munus)

Power of object-oriented programming with the elegance of functional programming.
Increase the robustness with reduced amount of code.
At the moment, in the experimental phase.
**[Documentation](https://munusphp.github.io/docs/start)**
Due to the lack of generic types, Munus achieves genericity with the help of [PHPStan](https://phpstan.org/blog/generics-in-php-using-phpdocs) `template` annotation.
Stream example: find the sum of the first ten squares of even numbers
```php
Stream::from(1)
    ->filter(fn($n) => $n%2===0)
    ->map(fn($n) => $n**2)
    ->take(10)
    ->sum();
```
Other examples:
```php
/** @var Stream $stream */
$stream = Stream::range(1, 10)->map(function(int $int): int {return $int * 5});
/** @var Option $option */
$option = Option::of(domainOperation());
/** @return Either */
function domainOperation(): Either {}
/** @var TryTo $result */
$result = TryTo::run(function(){throw new \DomainException('use ddd');});
$result->getOrElse(new Result())
```
The goal is to help achieve:
**Psalm was able to infer types for 100% of the codebase**
### Features
**Values:**
 - TryTo
 - Either
 - Option
 - Lazy
**Collections:**
 - Set
 - Stream (implemented as lazy linked list)
 - GenericList (implemented as immutable linked list)
 - Iterator
**Other:**
 - Tuple
### Roadmap
 - Pattern matching
 - Property checking
## Inspiration
This library is inspired by [vavr.io](https://www.vavr.io/)
## License
Munus is released under the MIT Licence. See the bundled LICENSE file for details.
## Author
[@ArkadiuszKondas](https://twitter.com/ArkadiuszKondas)