Chainy
No description available
Install / Use
/learn @crocodile2u/ChainyREADME
Chainy - a nicer way to apply a set of functions to a value
Have you ever written code like this?
$array = array_filter($array);
$array = array_map(
$array,
function($element) {
// ... manipulations ...
return $modifiedElement;
}
);
sort($array);
Know what? You could do the same in a more readable and nice way:
$chain = (new \chainy\Chain)
->filter()
->map(
function($element) {
// ... manipulations ...
return $modifiedElement;
}
)
->sort();
$array = $chain->apply($array);
Chainy is a pipeline of functions, where every next one gets input from the previous one's output. In the example above, when $chain->apply() is called on $array, it goes sequentially through filter(), map() and sort(). As you can expect, those methods are just wrappers for the PHP's built-in functions array_filter, array_map and sort.
This is how things go with chainy:
- Create new Chain instance.
- Setup the pipeline, adding elements to the chain (in this casem filter to get rid of empty element, map to apply some modifications to every element that survived filter, and then sort the resulting array).
- Call Chain->apply() on the input array. The result is the filtered, modified and sorted array.
$chain = (new \chainy\Chain)
+------> filter() --+
| |
| +--------------+
| |
| +-> map(function()...) --+
| |
| +------------------------+
| |
| +-> sort();
|
| $array = $chain->apply($array);
| |
|--------------------------+
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
