承接 cdn77/functions 相关项目开发

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

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

cdn77/functions

Composer 安装命令:

composer require cdn77/functions

包简介

PHP Functions

README 文档

README

GitHub Actions Code Coverage Downloads Packagist

Functions

absurd()

Function that should have never been called. Useful for default case in exhaustive matching.

assert_return()

Asserts the value via the expression and returns it.

It's useful when you want to assert inline so for example you can keep the arrow function in place.

It uses native assert() internally.

use function Cdn77\Functions\assert_return;

array_map(
    fn (mixed $value) => new RequiresInt(assert_return($value, is_int(...))),
    [1, 2, 3]
);

noop()

Does nothing. Useful e.g. for match expression that currently supports single-line expressions in blocks.

match ($val) {
  '1' => throw new Exception,
  '2' => foo(),
  default => noop(),
};

Ds

mapFromEntries()

Creates a map from an iterable of entries.

use function Cdn77\Functions\mapFromEntries;

$map = mapFromEntries([
  ['foo', 'bar'],
  ['baz', 'qux'],
]);

assert($map->get('foo') === 'bar');

mappedMapsFromIterable()

Groups an iterable into a Map<K, Map<KInner, V>> using a mapper that returns nested Pairs.

use Ds\Pair;
use function Cdn77\Functions\mappedMapsFromIterable;

$map = mappedMapsFromIterable(
    ['a' => 1, 'b' => 2, 'c' => 1],
    static fn (string $key, int $value) => new Pair($value, new Pair($key, $key . '_')),
);

assert($map->get(1)->get('a') === 'a_');
assert($map->get(1)->get('c') === 'c_');
assert($map->get(2)->get('b') === 'b_');

Iterable

find()

Finds a value in an iterable.

use function Cdn77\Functions\Iterable\find;

$iterable = [0, 1, 2, 3];
$option = find($iterable, static fn (mixed $_, int $value) => $value < 2);

assert($option->unwrap() === 0);

统计信息

  • 总下载量: 116.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固