All Projects → nunomaduro → Curryable

nunomaduro / Curryable

Licence: mit
An elegant and simple curry(f) implementation in PHP.

Projects that are alternatives of or similar to Curryable

Breadcrumbs
Laravel Breadcrumbs - An easy way to add breadcrumbs to your @Laravel app.
Stars: ✭ 169 (-1.74%)
Mutual labels:  laravel
Laravel Movies Example
Code for YouTube series on building a Laravel Movie Application
Stars: ✭ 171 (-0.58%)
Mutual labels:  laravel
Lapse
Laravel Self Hosted Tiny Error Tracking System With Notifications
Stars: ✭ 172 (+0%)
Mutual labels:  laravel
Lara Head
Easily setup SEO in your laravel project with lara-head ❤️ @code4mk
Stars: ✭ 169 (-1.74%)
Mutual labels:  laravel
Laravel Nova Nested Form
This package allows you to include your nested relationships' forms into a parent form.
Stars: ✭ 169 (-1.74%)
Mutual labels:  laravel
Laravel Debugbar
Laravel Debugbar (Integrates PHP Debug Bar)
Stars: ✭ 13,485 (+7740.12%)
Mutual labels:  laravel
Imall
基于Laravel5.2,Vue.js1.0的微信商城,用于熟悉 Laravel、Vuejs、Webpack、Gulp 的结合使用,已不维护及更新。(1MB单核基础服务器,浏览请耐心等待图片加载...)
Stars: ✭ 168 (-2.33%)
Mutual labels:  laravel
Creative Scala
Quick, graphical, fun introduction to programming in Scala.
Stars: ✭ 171 (-0.58%)
Mutual labels:  functional-programming
Laravel Selfupdater
This package provides some basic methods to implement a self updating functionality for your Laravel application. Already bundled are some methods to provide a self-update mechanism via Github or some private repository via http.
Stars: ✭ 170 (-1.16%)
Mutual labels:  laravel
Laradminator
Integration of Adminator into Laravel 6.x/7.x/8.x with RTL support
Stars: ✭ 170 (-1.16%)
Mutual labels:  laravel
Laravel Bridge
Package to use Laravel on AWS Lambda with Bref
Stars: ✭ 168 (-2.33%)
Mutual labels:  laravel
Scala Server Toolkit
Functional programming toolkit for building server applications in Scala.
Stars: ✭ 170 (-1.16%)
Mutual labels:  functional-programming
Koel
🐦 A personal music streaming server that works.
Stars: ✭ 13,105 (+7519.19%)
Mutual labels:  laravel
Fcm
Firebase Cloud Messaging (FCM) notifications channel for Laravel
Stars: ✭ 169 (-1.74%)
Mutual labels:  laravel
Hm Def
Runtime type checking for JS with Hindley Milner signatures
Stars: ✭ 171 (-0.58%)
Mutual labels:  functional-programming
Laravel Google Captcha
Google captcha for Laravel 5, Laravel 6 and Laravel 7, support multiple captcha on page
Stars: ✭ 168 (-2.33%)
Mutual labels:  laravel
Novapackages
Stars: ✭ 169 (-1.74%)
Mutual labels:  laravel
Laravel Route Attributes
Use PHP 8 attributes to register routes in a Laravel app
Stars: ✭ 171 (-0.58%)
Mutual labels:  laravel
Dv Php Core
Devless is a ready-made back-end for development of web or mobile applications. It is fully open source under the permissive Apache v2 license. This means that you can develop your front end without worrying about neither back-end code or the business risk of a proprietary backend-as-a-service.
Stars: ✭ 171 (-0.58%)
Mutual labels:  laravel
Multi Domain Laravel
An example of multi-domain/subdomain app in Laravel.
Stars: ✭ 171 (-0.58%)
Mutual labels:  laravel

Curryable

Build Status Total Downloads Latest Version License

About Curryable

This package is under development, please don't use it on production and wait for the stable release!

Curryable was created by, and is maintained by Nuno Maduro, and is an elegant and simple curry(f) implementation in PHP. Currying is an advanced technique of working with functions. It wraps the given expressions and arguments into a new function that resolves a value.

Installation & Usage

Requires PHP 7.2+

Create your package using Composer:

composer require nunomaduro/curryable

This helper usage is best described through example in the Laravel framework:

On routing

Route::get('/', curry('view', 'welcome'));

// Instead of
Route::get('/', function () {
    return view('welcome');
});
Route::get('user/{id}', curry(User::class)->find());
// Or with Eloquent macro
Route::get('user/{id}', User::curry()->find());

// Instead of
Route::get('user/{id}', function ($id) {
    return User::find($id);
});

On macros

Renaming the lower method to toLower:

Str::macro('toLower', curry()->lower());
// or with the global `strtolower`
Str::macro('toLower', curry('strtolower'));

// Instead of
Str::macro('toLower', function ($value) {
    return Str::lower($value);
});

On collections

Using the global strtoupper:

$collection = collect(['nuno'])->map(curry('strtoupper')); // ['NUNO']

// Instead of
$collection = collect(['nuno'])->map(function ($name) {
    return strtoupper($name);
});

Here is another example using the each:

// Calls User::create($user) foreach user
collect($users)->each(User::curry()->create());

// Instead of
$collection = collect($users)->map(function ($user) {
    return User::create($user);
});

Dispatching jobs:

dispatch(curry(Artisan::class)->call('horizon:terminate'));

// Instead of
dispatch(function () {
    Artisan::call('horizon:terminate');
});

Curry on class instance methods

With global helper:

$closure = curry($instance)->instanceMethodName();
$closure($first, $second);

$closure = curry($instance)->instanceMethodName($first);
$closure($second); // just need for the second argument

$closure = curry($instance)->instanceMethodName($first, $second);
$closure(); // no need for arguments

With trait NunoMaduro\Curryable\Curryable:

$closure = $instance->curry()->instanceMethodName();
$closure($first, $second);

$closure = $instance->curry()->instanceMethodName($first);
$closure($second); // just need for the second argument

$closure = $instance->curry()->instanceMethodName($first, $second);
$closure(); // no need for arguments

Curry on class static methods

// Curry on instance methods
$closure = curry(Instance::class)->staticMethodName();
$closure($first, $second);

$closure = curry(Instance::class)->staticMethodName($first);
$closure($second); // just need for the second argument

$closure = curry(Instance::class)->staticMethodName($first, $second);
$closure(); // no need for arguments

Curry on functions

// Curry on instance methods
$closure = curry('function_name');
$closure($first, $second);

$closure = curry('function_name', $first);
$closure($second); // just need for the second argument

$closure = curry('function_name', $first, $second);
$closure(); // no need for arguments

Contributing

Thank you for considering to contribute to Curryable. All the contribution guidelines are mentioned here.

You can have a look at the CHANGELOG for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: @enunomaduro

Support the development

Do you like this project? Support it by donating

License

curryable is an open-sourced software licensed under the MIT license.

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].