Download the PHP package majesko/fp-kit without Composer

On this page you can find all versions of the php package majesko/fp-kit. 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 fp-kit

majesko/fp-kit

A lightweight functional programming toolkit for PHP 8.2+. This library provides immutable data types, function composition utilities, and array helpers that enable a clean functional programming style in PHP.

Features

Table of Contents

Installation

Requires PHP 8.2 or higher.

Quick Start

Function Composition

pipe

Chains functions left-to-right, passing the result of each function to the next.

compose

Chains functions right-to-left (mathematical composition).

tap

Executes a side effect without changing the value (useful for debugging).

partial

Creates a new function with some arguments pre-filled.

Array Functions

Functional array manipulation utilities.

Result Type

Result represents an operation that can succeed (ok) or fail (err). It's perfect for error handling without exceptions.

Creating Results

Checking Results

Transforming Results

Pattern Matching

Real-World Example

Option Type

Option represents a value that may or may not exist, similar to null but composable.

Creating Options

Transforming Options

Pattern Matching

Interop with Result

Validation Type

Validation is similar to Result but accumulates multiple errors instead of short-circuiting on the first error. Perfect for form validation.

Creating Validations

Combining Validations

Lifting Functions

Pattern Matching

API Reference

Function Composition

Function Signature Description
pipe (callable ...$fns): callable Left-to-right function composition
compose (callable ...$fns): callable Right-to-left function composition
tap (callable $fn): callable Execute side effect without changing value
partial (callable $fn, mixed ...$args): callable Partial application

Array Functions

Function Signature Description
map (array $xs, callable $fn): array Transform each element
filter (array $xs, callable $fn): array Keep elements matching predicate
reduce (array $xs, callable $fn, mixed $init): mixed Reduce to single value
groupBy (array $xs, callable $fn): array Group by key function
indexBy (array $xs, callable $fn): array Create associative array by key

Result Type

Function Signature Description
ok (mixed $value): array Create success Result
err (mixed $error): array Create error Result
isOk (array $r): bool Check if Result is success
isErr (array $r): bool Check if Result is error
map (array $r, callable $fn): array Transform success value
bind (array $r, callable $fn): array Chain Result-returning operations
mapError (array $r, callable $fn): array Transform error value
unwrapOr (array $r, mixed $default): mixed Get value or default
fold (array $r, callable $ok, callable $err): mixed Extract value with handlers
matchResult (array $r, callable $ok, callable $err): mixed Pattern match

Option Type

Function Signature Description
some (mixed $value): array Create present Option
none (): array Create absent Option
isSome (array $o): bool Check if Option has value
isNone (array $o): bool Check if Option is empty
map (array $o, callable $fn): array Transform value if present
bind (array $o, callable $fn): array Chain Option-returning operations
unwrapOr (array $o, mixed $default): mixed Get value or default
fromNullable (?mixed $value): array Create from nullable value
fromArray (array $arr, int\|string $key): array Create from array key
toResult (array $o, mixed $error): array Convert to Result
matchOption (array $o, callable $some, callable $none): mixed Pattern match

Validation Type

Function Signature Description
valid (mixed $value): array Create valid Validation
invalid (array $errors): array Create invalid Validation
isValid (array $v): bool Check if valid
isInvalid (array $v): bool Check if invalid
errors (array $v): array Get error list
map (array $v, callable $fn): array Transform value if valid
combine (array $validations): array Combine, accumulating errors
lift (callable $fn, array ...$validations): array Apply function to validations
toResult (array $v): array Convert to Result
matchValidation (array $v, callable $valid, callable $invalid): mixed Pattern match

Testing

Run the test suite:

Contributing

Contributions are welcome! This project follows:

Please ensure all tests pass and code style checks succeed before submitting a PR.

License

MIT License. See LICENSE file for details.

Why fp-kit?

Modern PHP has powerful features like arrow functions, named arguments, and union types that make functional programming more ergonomic. This library provides:

Inspired by functional programming patterns from Rust, Haskell, and Scala, adapted for PHP's strengths.


All versions of fp-kit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 majesko/fp-kit contains the following files

Loading the files please wait ...