PHPackages                             zonuexe/functools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zonuexe/functools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zonuexe/functools
=================

Functional toolbox

0.2.0(10y ago)18511Apache-2.0PHP

Since Jan 21Pushed 9y ago2 watchersCompare

[ Source](https://github.com/zonuexe/php-functools)[ Packagist](https://packagist.org/packages/zonuexe/functools)[ RSS](/packages/zonuexe-functools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (8)Used By (0)

Teto Functools
==============

[](#teto-functools)

[![Package version](https://camo.githubusercontent.com/f812d4b1edb1e5841b0fd9f20f9769045e2f6736fea79d90064f5fbcf2a04e45/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6f6e756578652f66756e63746f6f6c732e7376673f7374796c653d666c6174)](https://packagist.org/packages/zonuexe/functools)[![Build Status](https://camo.githubusercontent.com/9a7e8dc94fa565cd481c40c6c1ed239fab323d0e4560e7afb98e86e8c5080976/68747470733a2f2f7472617669732d63692e6f72672f42616775657474655048502f46756e63746f6f6c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BaguettePHP/Functools)[![Packagist](https://camo.githubusercontent.com/19a4776901d0e09441a8fe215cf1926b42407785f1d2b5860da12db7ee22b910/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6f6e756578652f66756e63746f6f6c732e7376673f7374796c653d666c6174)](https://packagist.org/packages/zonuexe/functools)[![Coverage Status](https://camo.githubusercontent.com/fc7fa86ad0fbd2db8f89dc192fc182145380e10520ed5a610d95363ab5df39d4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f42616775657474655048502f46756e63746f6f6c732f62616467652e737667)](https://coveralls.io/r/BaguettePHP/Functools)

Functional toolbox for PHP

Installation
------------

[](#installation)

### Composer

[](#composer)

```
composer require zonuexe/functools

```

Features
--------

[](#features)

- `Functools\Operator`
    - Operator Expression wrapper
        - Binary operator `1 + 2` `$a === "abc"` `$date instanceof '\Datetime'`
        - Conditional operator `$cond ? $then : $else`
        - Lazy Conditional operator `$cond($v) ? $then($v) : $else($v)` ([thunk](http://en.wikipedia.org/wiki/Thunk))
    - [Referential transparent](http://en.wikipedia.org/wiki/Referential_transparency_%28computer_science%29) version [sorting array functions](http://php.net/manual/array.sorting.php).
        - You can `array_map(f::op('ksort'), $arrays)` !
    - Language-construct wrapper
        - `echo`, `print`, `eval`, `require`, `require_once`, `include`, `include_once`
        - limited support: `array`, `isset`, `empty`
- `Functools::partial(callable $callback, array $arguments, int $pos)`
    - Partial application for [callable](http://php.net/manual/language.types.callable.php) (`arary_map` friendly)
- `Functools::arity(callable $callback)`
    - Analyze [arity](http://en.wikipedia.org/wiki/Arity)(number of arguments) of `$callback`.
- `Functools::curry(callable $callback)`
    - [Currying](http://en.wikipedia.org/wiki/Currying) `$callback` object.
- `Functools::op(string $symbol, [array $arguments, int $pos])`
    - Get callable object (and partial application.)
- `Functools::compose(callable $callback,...)`
    - [Function composition](http://en.wikipedia.org/wiki/Function_composition_%28computer_science%29).
- `Functools::pipe(mixed $value, callable $callback...)`
    - [Pipeline](https://en.wikipedia.org/wiki/Pipeline_(Unix)) like functions composing
- `Functools::tuple(mixed $item,...)`
    - Make n-[Tuple](http://en.wikipedia.org/wiki/Tuple).
- `Functools::fix(callable $callback)`
    - [Anonymous recursion](http://en.wikipedia.org/wiki/Anonymous_recursion) ([fixed-point combinator](http://en.wikipedia.org/wiki/Fixed-point_combinator))
- `Functools::memoize(callable $callback, [array $cache])`
    - Function optimizer using [Memoization](https://en.wikipedia.org/wiki/Memoization).
    - This feature will help in optimization of transparent reference explicit definition equation.

Iteration
---------

[](#iteration)

This library does not have iterator. You will be able to combine it by selecting a favorite of iterator library.

- PHP [`array`](http://php.net/manual/language.types.array.php) and functions
    - [PHP: array\_map - Manual](http://php.net/manual/function.array-map.php)
    - [PHP: array\_reduce - Manual](http://php.net/manual/function.array-reduce.php)
    - [PHP: array\_filter - Manual](http://php.net/manual/function.array-filter.php)
- [Underbar.php - A collection processing library for PHP, like Underscore.js.](http://emonkak.github.io/underbar.php/)
    - [emonkak/underbar.php](https://github.com/emonkak/underbar.php)
- Ginq
    - [akanehara/ginq](https://github.com/akanehara/ginq)
- nikic\\iter
    - [nikic/iter](https://github.com/nikic/iter)

Usage
-----

[](#usage)

Japanese version:

### Short syntax

[](#short-syntax)

```
use Teto\Functools as f;
```

### f::partial()

[](#fpartial)

```
$comma = f::partial("implode", [", "]);
$comma(range(1, 10));
// "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"

$join_10 = f::partial("implode", [1 => range(1, 10)], 0);
$join_10("@");
// "1@2@3@4@5@6@7@8@9@10"
$join_10("\\");
=> "1\\2\\3\\4\\5\\6\\7\\8\\9\\10"

$sleep3 = f::partial("sleep", [3]);
$sleep3();
$sleep3("foo"); // Error!

$sleep3 = f::partial("sleep", [3], -1);
$sleep3("foo"); // OK!
```

### f::op()

[](#fop)

```
$add = f::op("+");
$add(2, 3); // (2 + 3) === 5

$add_1 = f::op("+", [1]);
$add_1(4);  // (1 + 4) === 5

$half = f::op("/", [1 => 2], 0);
$half(10);  // (10 / 2) === 5
```

### f::tuple()

[](#ftuple)

```
$teto  = f::tuple("Teto Kasane",  31, "2008-04-01", "Baguette");
$ritsu = f::tuple("Ritsu Namine", 6,  "2009-10-02", "Napa cabbage");

// index access
$teto[0]; // "Teto Kasane"
$teto[1]; // 31
$teto[2]; // "2008-04-01"
$teto[3]; // "Baguette"

// property access

$tetop  = f::tuple("name", "Teto Kasane",  "age", 31, "birthday", "2008-04-01", "item", "Baguette");
$ritsup = f::tuple("name", "Ritsu Namine", "age",  6, "birthday", "2009-10-02", "item", "Napa cabbage");
$tetop->pget("name");     // "Teto Kasane"
$tetop->pget("age");      // 31
$tetop->pget("birthday"); // "2008-04-01"
$tetop->pget("item");     // "Baguette"
```

### f::fix()

[](#ffix)

```
$fib = f::fix(function ($fib) {
    return function ($x) use ($fib) {
        return ($x < 2) ? 1 : $fib($x - 1) + $fib($x -2);
    };
});

$fib(6); // 13
```

### f::memoize()

[](#fmemoize)

```
// simple fibonacci function. But, very very slow.
$fib1 = function ($n) use (&$fib1) {
    return ($n < 2) ? $n : $fib1($n - 1) + $fib1($n - 2);
};

// simple fibonacci function too. very fast!
$fib2 = f::memoize(function ($n) use (&$fib2) {
    return ($n < 2) ? $n : $fib2($n - 1) + $fib2($n - 2);
}, [0, 1]);
```

Copyright
---------

[](#copyright)

see `./LICENSE`.

```
Functional toolbox
Copyright (c) 2015 USAMI Kenta

```

Teto Kasane
-----------

[](#teto-kasane)

I love [Teto Kasane](http://utau.wikia.com/wiki/Teto_Kasane). (ja: [Teto Kasane official site](http://kasaneteto.jp/))

```
　　　　　 　r /
　 ＿＿ , --ヽ!-- .､＿
　! 　｀/::::;::::ヽ l
　!二二!::／}::::丿ハﾆ|
　!ﾆニ.|:／　ﾉ／ }::::}ｺ
　L二lイ　　0´　0 ,':ﾉｺ
　lヽﾉ/ﾍ､ ''　▽_ノイ ソ
 　ソ´ ／}｀ｽ /￣￣￣￣/
　　　.(_:;つ/  0401 /　ｶﾀｶﾀ
 ￣￣￣￣￣＼/＿＿＿＿/

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Recently: every ~76 days

Total

7

Last Release

3820d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1cc4bc1729b858086681a12494fda6cced8f26db3d0928ae4d81c68ddf8dc06?d=identicon)[zonuexe](/maintainers/zonuexe)

---

Top Contributors

[![zonuexe](https://avatars.githubusercontent.com/u/822086?v=4)](https://github.com/zonuexe "zonuexe (63 commits)")

---

Tags

functional-programmingphpfunctionalsortingmemoizationtuplecons

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zonuexe-functools/health.svg)

```
[![Health](https://phpackages.com/badges/zonuexe-functools/health.svg)](https://phpackages.com/packages/zonuexe-functools)
```

###  Alternatives

[lstrojny/functional-php

Functional primitives for PHP

2.0k7.3M48](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[kyslik/column-sortable

Package for handling column sorting in Laravel 6.x

6485.6M21](/packages/kyslik-column-sortable)[mottie/tablesorter

tablesorter (FORK) is a jQuery plugin for turning a standard HTML table with THEAD and TBODY tags into a sortable table without page refreshes. tablesorter can successfully parse and sort many types of data including linked data in a cell.

2.6k223.5k](/packages/mottie-tablesorter)[lambdish/phunctional

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

381368.5k](/packages/ihor-nspl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
