j45l/functional-php
Composer 安装命令:
composer require j45l/functional-php
包简介
Functional primitives for PHP
关键字:
README 文档
README
Functional primitives for PHP 8.2+, inspired by several functional libraries such as lstrojny/functional-php, Typelevel Cats, Scala, SML, etc.
This library provides a small, opinionated toolbox to write PHP in a functional style: working with collections as first-class values, composing behaviour out of small functions, and keeping side effects contained.
What you get
Collection filtering and selection
Pick elements out of any iterable without hand-rolling loops: first / last / head / tail, butLast, take,
pluck, select / reject, best / worst, and traverse for matching against nested tree-like data.
Collection transformation
Reshape and combine collections: map, flatMap, reindex, fold / foldRight, reduce / reduceRight, sum,
merge / mergeGenerator, zip / unzip, concat, cartesianProduct, crossCompareSet, from / upTo,
recurseTimes, and conversions between iterables, arrays and generators (toArray, toGenerator, toIterable,
yieldIterable, unindex).
Function composition, partial application and currying
Build new functions out of existing ones: compose, pipe, partial, partialRight.
Logic and predicate helpers
Combine and negate predicates and ask boolean questions of collections: every, some, none, not.
Value functions
Tiny building blocks that show up everywhere when composing: identity, nop, trueFn, falseFn, value, with.
Object & type functions
Work with values whose type or shape needs checking or adjusting: isAOr, isClosureOr, cloneWith (clones an object
and runs a closure bound to it, so even private properties can be set on the copy).
Loop and effect functions
Express imperative-shaped work without leaving the functional style: doWhile, doUntil, doEach, also (run a side
effect and pass the value through), delay, tryOrThrow.
Optimization
tailRecursion decorates a recursive closure with a trampoline so deep recursion does not blow the PHP stack, and
MemoizeTrait caches results of pure methods.
Sequences
Lazy numeric sequences as iterable objects: LinearSequence, ExponentialSequence, FibonacciSequence, plus the
underlying Sequence / SequenceIterator to roll your own.
Tuples
Simple immutable Pair and Triplet value objects, with factory helpers — useful as return types for functions that
naturally produce two or three related values (and as the output of crossCompareSet).
PHPUnit helpers
A handful of assertion helpers in PHPUnitFunctions.php for testing code written in this style.
Design notes
- The library targets PHP 8.2+.
- Most functions accept any
iterableas input and return anarray. Some fully consume generators — beware of infinite ones. - Only
\Closureis accepted where a function is expected (not the loosercallable). Wrap anything else in an arrow function, e.g.fn(...$a) => strtolower(...$a).
Install
composer require j45l/functional-php
Documentation
Per-function reference with signatures and examples: Functions.
For anything not covered there, the unit tests under tests/ are the source of truth.
j45l/functional-php 适用场景与选型建议
j45l/functional-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.73k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「functional」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 j45l/functional-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 j45l/functional-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 j45l/functional-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Connection 'Db' codeception module to 'Yii2' module database settings
Functional library for php with proper currying
Iteration tools for PHP
A PHP library with partial functions suitable for the pipe operator
Centralized monorepository for functional libraries
Json schema module for validate response by json schema for codeception test framework
统计信息
- 总下载量: 20.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-15