All Projects → adhocore → With

adhocore / With

Licence: mit
With provides object like fluent interface for scalars and non-objects

Projects that are alternatives of or similar to With

Fluent Reveal Effect
Fluent Reveal Effect JavaScript library for web
Stars: ✭ 164 (+1071.43%)
Mutual labels:  fluent-interface
csvplus
csvplus extends the standard Go encoding/csv package with fluent interface, lazy stream operations, indices and joins.
Stars: ✭ 67 (+378.57%)
Mutual labels:  fluent-interface
Thumbnailator
Thumbnailator - a thumbnail generation library for Java
Stars: ✭ 3,845 (+27364.29%)
Mutual labels:  fluent-interface
FluentInterfaceCreator
Tool to create fluent interface files
Stars: ✭ 58 (+314.29%)
Mutual labels:  fluent-interface
Dexiom.EPPlusExporter
A very simple, yet incredibly powerfull library to generate Excel documents out of objects, arrays, lists, collections, etc.
Stars: ✭ 19 (+35.71%)
Mutual labels:  fluent-interface
windows-ui-web
Build windows fluent UI apps or web apps using Html, CSS & JavaScript. Comes with rich native like components, icon sets. Used as fast prototyping tool for Windows environment platforms.
Stars: ✭ 98 (+600%)
Mutual labels:  fluent-interface
Mailbody
Create transactional email with a fluent interface (.net)
Stars: ✭ 151 (+978.57%)
Mutual labels:  fluent-interface
Chainly
Make any .NET object a fluent interface regardless if you have the source code or not!
Stars: ✭ 19 (+35.71%)
Mutual labels:  fluent-interface
fluentcheck
Fluent assertions for Python
Stars: ✭ 79 (+464.29%)
Mutual labels:  fluent-interface
Acf Fluent
✒️ A fluent interface for the Advanced Custom Fields WordPress plugin
Stars: ✭ 264 (+1785.71%)
Mutual labels:  fluent-interface
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (+85.71%)
Mutual labels:  fluent-interface
1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (+242.86%)
Mutual labels:  fluent-interface
php-underscore
PHP underscore inspired &/or cloned from _.js, with extra goodies like higher order messaging
Stars: ✭ 42 (+200%)
Mutual labels:  fluent-interface
Filehound
Flexible and fluent interface for searching the file system
Stars: ✭ 190 (+1257.14%)
Mutual labels:  fluent-interface
Pnp Js Core
Code moved to https://github.com/pnp/pnpjs. This repository is archived.
Stars: ✭ 382 (+2628.57%)
Mutual labels:  fluent-interface
Jaque
Lets Java 8 Lambdas to be represented as objects in the form of expression trees at runtime
Stars: ✭ 152 (+985.71%)
Mutual labels:  fluent-interface
php-currency-api
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.
Stars: ✭ 17 (+21.43%)
Mutual labels:  fluent-interface
Rumble 4 Android
Dead simple Android library for API independant Vibration functionality with fluent interface.
Stars: ✭ 26 (+85.71%)
Mutual labels:  fluent-interface
Validation
The most awesome validation engine ever created for PHP
Stars: ✭ 5,484 (+39071.43%)
Mutual labels:  fluent-interface
csharp-http-client
Twilio SendGrid's C# HTTP Client for calling APIs
Stars: ✭ 25 (+78.57%)
Mutual labels:  fluent-interface

adhocore/with

Latest Version Travis Build Scrutinizer CI Codecov branch StyleCI Software License

  • Objectify scalars and non objects
  • Fluent method chaining instead of nested function calls
  • For PHP7

Installation

composer require adhocore/with

Usage

use function Ahc\with;
// OR
use Ahc\With\With;

$val  = ['a' => 10, 'b' => 12, 'c' => 13];
$with = with($val) // OR (new With($val))
    ->array_values()
    // _ at the end means the current value is appended to the supplied arguments (default is prepend).
    ->array_map_(function ($v) { return $v + 2; })
    ->array_sum()
;

// Get the final result
echo $with(); // 41

// Passing value through closures or class methods:
with($value)->via(function ($val) { return $val; });
with($value)->via([new SomeClass, 'method']);

Why

TL;DR: Provides more intuitiveness, comprehensibility and less cognitive overhead than nested function calls.

Did you ever had to pass a scalar/non-object through many layers of functions? Then you might have probably ended up with having to call the first the function which had to be called at the last logically. For example if you want to sum the keys of an array after adding 2 to them?

// Without:
array_sum(array_map(function ($a) { return $a + 2; }, array_keys($array)));

// With:
with($array)->array_keys()->array_map_(function ($a) { return $a + 2; })->array_sum();
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].