All Projects → vector-php → vector

vector-php / vector

Licence: MIT license
A PHP functional programming library.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to vector

fib-anyon
An implementation of Fibonacci Anyons in Haskell
Stars: ✭ 18 (-5.26%)
Mutual labels:  functional, vector
Immutable Tuple
Immutable finite list objects with constant-time equality testing (===) and no memory leaks.
Stars: ✭ 29 (+52.63%)
Mutual labels:  memoization, functional
invokable
Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs).
Stars: ✭ 40 (+110.53%)
Mutual labels:  memoization, currying
hawkweed
Yet another implementation of missing functions for Python
Stars: ✭ 20 (+5.26%)
Mutual labels:  functional, currying
vec-la-fp
↗️ A tiny (functional) 2d linear algebra library
Stars: ✭ 21 (+10.53%)
Mutual labels:  functional, vector
PartialFunctions.jl
A small package to simplify partial function application
Stars: ✭ 34 (+78.95%)
Mutual labels:  functional, currying
Funky
Funky is a functional utility library written in Objective-C.
Stars: ✭ 41 (+115.79%)
Mutual labels:  functional
react-functional-select
Micro-sized & micro-optimized select component for React.js
Stars: ✭ 165 (+768.42%)
Mutual labels:  functional
peds
Type safe persistent/immutable data structures for Go
Stars: ✭ 57 (+200%)
Mutual labels:  functional
profiletool
Home to the QGis Profiletool plugin. Initial work on this fork was partially funded by the C.A. La Rioja
Stars: ✭ 23 (+21.05%)
Mutual labels:  vector
avatarmake
Easily make your own cartoon avatar base on d3.js
Stars: ✭ 34 (+78.95%)
Mutual labels:  vector
autoload
Aplus Framework Autoload Library
Stars: ✭ 18 (-5.26%)
Mutual labels:  autoload
matlib
Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics, http://friendly.github.io/matlib/
Stars: ✭ 55 (+189.47%)
Mutual labels:  vector
Stretch
KiCad to SVG and then back again
Stars: ✭ 56 (+194.74%)
Mutual labels:  vector
hack
Kubernetes security and vulnerability tools and utilities.
Stars: ✭ 56 (+194.74%)
Mutual labels:  vector
polyrpc
PolyRPC, A multi-tier functional programming language
Stars: ✭ 16 (-15.79%)
Mutual labels:  functional
micro
Functional prooph for microservices
Stars: ✭ 53 (+178.95%)
Mutual labels:  functional
FTAPIKit
Declarative and generic REST API framework using Codable.
Stars: ✭ 18 (-5.26%)
Mutual labels:  functional
dry-transformer
Data transformation toolkit
Stars: ✭ 59 (+210.53%)
Mutual labels:  functional
SuperformulaSVG
2D superformula line-art generator built in Processing, with SVG export for use in digital fabrication workflows.
Stars: ✭ 40 (+110.53%)
Mutual labels:  vector

Vector Core Badge Status

The Elevator Pitch

Vector gives you php functional superpowers.

  • The evolution:

    • Native PHP
        array_sum(
            array_map(
                fn($a) => $a + 1,
                [1, 2, 3]
            )
        );
        // 9
      • 👎 More than 1 or 2 function chains is unmaintainable
    • Laravel Collections
        collect([1, 2, 3])
            ->map(fn($a) => $a + 1)
            ->sum();
            // 9
      • 👍 More than 1 or 2 function chains is unmaintainable
      • 👎 Unfortunately you can't do this with every type in the same elegant way (only works with collections)
    • Vector
         vector([1, 2, 3])
             ->pipe(Arrays::map(Math::add(1))) // or `fn($a) => $a + 1)` 
             ->pipe(Math::sum())();
             // [2, 3, 4]
      • 👍 Works super similarly to collections, but just accepts & returns normal arrays (no ->toArray()-ing necessary)
      • 👍 Works super similarly to collections for everything else too!
      • 👎 Unfortunately it is an extra dependency (we don't have the native pipe operator yet https://wiki.php.net/rfc/pipe-operator-v2)
  • You can add currying to any function, it isn't only limited to Vector built ins.

    • Module::curry('explode')(',')('a,b,c')(PHP_INT_MAX) // ['a', 'b', 'c']

PHP Version Support

  • 8.0+

Install

composer require vector/core

Show Me Some More Code

More automatic currying.

$addOne = Arrays::map(Math::add(1));
$addOne([1, 2, 3]); // [2, 3, 4]

First class composition (Functional Pipelines).

$addSix = Lambda::compose(Math::add(4), Math::add(2)); // (Or ::pipe for the opposite flow direction)
$addSix(4); // 10;

Pattern Matching (Maybe & Result monads included).

Pattern::match([
    fn(Just $value) => fn ($unwrapped) => $unwrapped,
    fn(Nothing $value) => 'nothing',
])(Maybe::just('just')); // 'just'

Granular control flow (without try/catch).

$errorHandler = function (Err $err) {
    return Pattern::match([
        function (QueryException $exception) {
            Log::info($exception);
            return response(404);
        },
        function (DBException $exception) {
            Log::error($exception);
            return response(500);
        },
    ]);
};

return Pattern::match([
    fn(Ok $value) => fn (User $user) => $user,
    $errorHandler
])(Result::from(fn() => User::findOrFail(1)));

Make your own modules with auto-curried methods

use Vector\Core\Curry;
use Vector\Core\Module;

class MyModule
{
    use Module;
    
    #[Curry]
    protected static function myCurriedFunction($a, $b)
    {
        return $a + $b;
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].