Git Product home page Git Product logo

phunctional's Introduction

Phunctional, because functional programming matters.

Lambdish MIT License Version Monthly Downloads Travis Build Status

Lambdish's Phunctional is a little library that tries to bring to PHP some aspects of functional programing with util high order functions and functions for manage iterables.


About

Phunctional is heavily inspired by Clojure and some other PHP libraries like iter, compose and felpado.

The main principles that we have in mind developing this library are:

  • A collection can be any iterable PHP object, arrays or generators
  • Favor composition vs inheritance
  • Be lazy when you can
  • Avoid state, state is (usually) evil!
  • Simplicity over easiness
  • Break the above rules if it makes sense

All of this can be resumed with a word: Immutability.

Installation

To install it with composer:

composer require lambdish/phunctional

Simple usage

The first is to import every function you're going to use, for example:

use function Lambdish\phunctional\map;

And then you'll be able to use it:

map(
    function ($number) {
        return $number + 10;
    },
    [1, 2, 3, 4, 5]
);

// => [11, 12, 13, 14, 15]

And do something more complex like:

use function Lambdish\Phunctional\pipe;
use const Lambdish\Phunctional\{filter_null, reverse, first};

$lastNonNullableValue = pipe(filter_null, reverse, first);

$lastNonNullableValue(['first', null, 'other', 'last non nullable', null, null]);

// => "last non nullable"

Here we're using the provided constants, that acts like an alias for the functions full qualified namespace (and therefore, are callable).

Documentation

You can find the functions documentation here.

phunctional's People

Contributors

rgomezcasas avatar eloipoch avatar jorgeavilacardenosa avatar jordicabezudo avatar letnando avatar odelrio avatar ticdenis avatar diyankk avatar fnandot avatar felixgomez avatar gmadorell avatar joanmasoletgo avatar pfazzi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.