From 87896f917a0bf73ef8cb21b9dff5d68747ad7735 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Sat, 15 Oct 2022 12:36:11 +0800 Subject: [PATCH] doc: add document for pipeline --- docs/function.md | 38 ++++++++++++++++++++++++++++++++++++++ docs/function_zh-CN.md | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/docs/function.md b/docs/function.md index c6cdf62..d9eb820 100644 --- a/docs/function.md +++ b/docs/function.md @@ -26,6 +26,7 @@ import ( - [Compose](#Compose) - [Debounced](#Debounced) - [Delay](#Delay) +- [Pipeline](#Pipeline) - [Watcher](#Watcher)
@@ -300,6 +301,43 @@ func main() { ``` +### Pipeline + +

Pipeline takes a list of functions and returns a function whose param will be passed into +the functions one by one.

+ +Signature: + +```go +func Pipeline[T any](funcs ...func(T) T) func(T) T +``` +Example: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/function" +) + +func main() { + addOne := func(x int) int { + return x + 1 + } + double := func(x int) int { + return 2 * x + } + square := func(x int) int { + return x * x + } + + f := Pipeline(addOne, double, square) + + fmt.Println(f(2)) //36 +} +``` + ### Watcher diff --git a/docs/function_zh-CN.md b/docs/function_zh-CN.md index c8af436..59b082c 100644 --- a/docs/function_zh-CN.md +++ b/docs/function_zh-CN.md @@ -26,6 +26,7 @@ import ( - [Compose](#Compose) - [Debounced](#Debounced) - [Delay](#Delay) +- [Pipeline](#Pipeline) - [Watcher](#Watcher)
@@ -300,6 +301,44 @@ func main() { +### Pipeline + +

执行函数pipeline.

+ +函数签名: + +```go +func Pipeline[T any](funcs ...func(T) T) func(T) T +``` +例子: + +```go +package main + +import ( + "fmt" + "github.com/duke-git/lancet/v2/function" +) + +func main() { + addOne := func(x int) int { + return x + 1 + } + double := func(x int) int { + return 2 * x + } + square := func(x int) int { + return x * x + } + + f := Pipeline(addOne, double, square) + + fmt.Println(f(2)) //36 +} +``` + + + ### Watcher

Watcher 用于记录代码执行时间。可以启动/停止/重置手表定时器。获取函数执行的时间。