Download the PHP package pinkcrab/function-constructors without Composer

On this page you can find all versions of the php package pinkcrab/function-constructors. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package function-constructors

The PinkCrab FunctionConstructors library.

PHPUnit codecov Scrutinizer Code Quality Packagist Downloads GitHub tag (latest by date)


This library provides a small selection of functions for making functional programming a little cleaner and easier in php.

Setup

Can be included into your project using either composer or added manually to your codebase.

Via Composer

$ composer require pinkcrab/function-constructors

Via Manual Loader

If you wish to use this library within WordPress or other PHP codebase where you do not or cannot use composer, you can use the FunctionsLoader class. Just clone the repo into your codebase and do the following.

All of our functions are namespaced as PinkCrab\FunctionConstructors\{lib}. So the easiest way to use them is to use with an alias. Throughout all the docs on the wiki we use the following aliases.

Usage

At its core, the Function Constructors library is designed to make using PHP easier to use in a functional manor. With the use of functions compose() and pipe() its possible to construct complex functions, from simpler ones.

Function Composition and Piping

pipe()

PLEASE NOTE THIS HAS CHANGED IN VERSION 2.0.0, using compose() is now the preferred method.

Using pipe(mixed $value, callable ...$callables) and pipeR() *, allows you to pass a value through a chain of callables. The result of the 1st function, is passed as the input the 2nd and so on, until the end when the final result is returned.

The rest of this library makes it easier to use standard php functions as callables, by defining some of the parameters up front.

compose()

Piping is ideal when you are working with a single value, but when it comes to working with Arrays or writing callbacks, compose() is much more useful.

compose(callable ...$callables) , composeR(callable ...$callables) , composeSafe(callable ...$callables) and composeTypeSafe(callable $validator, callable ...$callables) all allow you to create custom Closures.

You can use composeTypeSafe() if you want to pass the return of each callable through a validator before being passed to the next. If the validator fails, the rest of the chain will be skipped and null will be returned.


Working with Records

It is possible to work with the properties of Records (arrays and objects). Indexes or Properties can be checked, fetched and set using some of the GeneralFunctions .

Reading Properties

You can check if a property exists, get its value or compare it an defined value.

pluckProperty() can also be used if you need to traverse nested properties/indexes of either arrays or objects also handles ArrayAccess objects, set with array syntax see example on compose()

Writing Properties

Its also possible to write properties of objects and set values to indexes in arrays using the setProperty() function. More complex structures can also be created using the Record Encoder


String Functions

Much of the string functions found in this library act as wrappers for common standard (PHP) library functions, but curried to allow them to be easier composed with.

String Manipulation

There is a collection of functions with make for the concatenation of strings.

String Contents

There is a collection of functions that be used to check the contents of a string.

Str\isBlank() can be used when composing a function, thanks to the Functions::isBlank constant.

Sub Strings

There is a series of functions that can be used to work with substrings.

See more of the Strings functions on the wiki


Number Functions

Much of the number functions found in this library act as wrappers for common standard (PHP) library functions, but curried to allow them to be easier composed with.

Basic Arithmetic

You can do some basic arithmetic using composable functions. This allows for the creation of a base value, then work using the passed value.

All these functions allow the use of INT or FLOAT only, all numerical strings must be cast before being used. Will throw TypeError otherwise.

Multiple and Modulus

It is possible to do basic modulus operations and working out if a number has a whole factor of another.

Array Functions

As you can imagine there are a large number of functions relating to arrays and working with them.

Map

This library contains a large number of variations of array_map , these can all be pre composed, using the other functions to be extremely powerful and easy to follow.

There is flatMap() and mapWith() also included, please see the wiki.

Filter and Take

There is a large number of composible functions based around array_filter() . Combined with a basic set of take*() functions, you can compose functions to work with lists/collections much easier.

Filter is great if you want to just process every result in the collection, the take() family of functions allow for controlling how much of an array is filtered

Fold and Scan

Folding or reducing an a list is a pretty common operation and unlike the native array_reduce you have a little more flexibility.

You also have access to foldR() and scanR() which will iterate through the array backwards.

Grouping and Partitioning

Function Constructor has a number of functions which make it easy to group and partition arrays

It is possible to chunk and split arrays, see the wiki for more.

Sorting

The native PHP sort functions are tricky with a functional approach, as they sort via reference, rather than by a return value. The Function Constructor library covers all native sorting as partially applied functions.


Contributions

If you would like to contribute to this project, please feel to fork the project on github and submit a pull request.


For more details, please read the wiki

Changes


All versions of function-constructors with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pinkcrab/function-constructors contains the following files

Loading the files please wait ....