承接 baethon/phln 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

baethon/phln

Composer 安装命令:

composer require baethon/phln

包简介

Set of small utility functions. Inspired by Ramda.

README 文档

README

Build Status Scrutinizer Code Quality

baethon/phln

Set of small utility functions.

Heavily inspired by Ramda.js, adapted for PHP needs.

Installation

composer require baethon/phln

Example usage

use Baethon\Phln\Phln as P;

$aboveMinPoints = P::compose(P::lte(50), P::prop('score'));
$onlyPhp = P::pathEq('language.name', 'PHP');

$topScores = collect($users)
    ->filter(P::both($aboveMinPoints, $onlyPhp));

Note: in the docs P will be used as an alias to Baethon\Phln\Phln.

Currying

Phln methods are loosely curried. A N-ary method will return a function until all arguments are provided.

$foo = P::curryN(2, function ($left, $right) {
    return $left + $right;
});

$foo(1); // returns instance of \Closure
$foo(1, 2); // 3
$foo(1)(2); // 3

Partial application

Partial application is possible with combination of P::partial() and P::__ const. Partial returns a function which accepts arguments which should "fill" gap of missing arguments for callable.

$foos = [1, 2, 3];
$mapFoos = P::partial('\\array_map', [P::__, $foos]);
$mapFoos(function ($f) {
    return $f + 100;
}); // [100, 200, 300]

Function composition

For function composition phln provides pipe() and compose() functions.

$allFoos = P::pipe(
    P::filter(P::lte(5)),
    P::map(P::always('foo'))
);

$firstFoo = P::compose(P::head(), $allFoos);

$allFoos([4, 5, 6]); // ['foo', 'foo']
$firstFoo([4, 5, 6]); // 'foo'

Using methods as references

Some of phln methods accept callable as an argument.

To pass another macro as a reference call it without any arguments.

$collection = [1, 2, 3, 4];
P::reduce(P::sum(), $collection); // 10

Also, you can use P::raw() method wich returns uncurried macro, or pointer to Phln method.

Extending

Baethon\Phln\Phln is macroable. This means that it can be extened using macro() method:

P::macro('foo', function () {
    return 'foo';
});

P::foo(); // 'foo'

Note about objects

The library takes terminology from Ramda. In most cases, it's perfectly fine, until one gets to the concept of object.

Ramda treats objects as dictionaries. In JavaScript, there's only one type which can act as a dictionary. It's ... object.

In PHP things get complicated. It's possible to use arrays and objects as dictionaries. This way Phln has to treat both of those types as an object.

For compatibility reason, all functions which return object will return array.

Testing

./vendor/bin/phpunit

baethon/phln 适用场景与选型建议

baethon/phln 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 755 次下载、GitHub Stars 达 17, 最近一次更新时间为 2017 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 baethon/phln 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 baethon/phln 我们能提供哪些服务?
定制开发 / 二次开发

基于 baethon/phln 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 755
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-07