Skip to content

Repository files navigation

Munus

Minimum PHP Versiongithub actionLatest Stable VersioncodecovTotal DownloadsGitHub

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

Due to the lack of generic types, Munus achieves genericity with the help of PHPStantemplate annotation.

Stream example: find the sum of the first ten squares of even numbers

Stream::from(1)
->filter(fn($n) => $n%2===0)
->map(fn($n) => $n**2)
->take(10)
->sum();

Other examples:

/** @var Stream<int> $stream */$stream = Stream::range(1, 10)->map(function(int$int): int {return$int * 5});
/** @var Option<Success> $option */$option = Option::of(domainOperation());
/** @return Either<Failure,Success> */functiondomainOperation(): Either {}
/** @var TryTo<Result> $result */$result = TryTo::run(function(){thrownew \DomainException('use ddd');});
$result->getOrElse(newResult())

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

License

Munus is released under the MIT Licence. See the bundled LICENSE file for details.

Author

@ArkadiuszKondas

About

Power of object-oriented programming with the elegance of functional programming in PHP.

Topics

Resources

Contributing

Stars

168 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages