From 538de9e66285c134fc9c077e0faf9a4ee580e47d Mon Sep 17 00:00:00 2001 From: Dima Kossovich Date: Thu, 23 Nov 2023 23:27:58 +0200 Subject: [PATCH] updated README.md --- README.md | 24 ++++++++++++++++++++++++ coverage_badge.png | Bin 2384 -> 2483 bytes example/{main.go => main._go} | 0 pkg/pipe/prefixpipe.go | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) rename example/{main.go => main._go} (100%) diff --git a/README.md b/README.md index d88df70..9072df8 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ Also [here](https://macias.info/entry/202212020000_go_streams.md) is some **perf - [Easy type conversion for Pipe[any]]( #easy-type-conversion-for-pipe[any]) - [Error handling](#error-handling) - [To be done](#to-be-done) +- [Using prefix `Pipe` to transform `Pipe` type](#using-prefix-pipe-to-transform-pipe-type) +- [Using `ff` package to write shortened pipes](#using-ff-package-to-write-shortened-pipes) +- [Look for useful functions in `Pipies` package](#look-for-useful-functions-in-pipies-package) - [Examples](#examples) - [Basic example](#basic-example) - [Example using `Func` and `Take`](#example-using-func-and-take) @@ -161,6 +164,27 @@ In addition to the functions described above, the `pipe` package also provides s Also it is highly recommended to get familiarize with the `pipies` package, containing some useful *predecates*, *comparators* and *accumulators*. +### Using prefix `Pipe` to transform `Pipe` type + +You may found that using `Erase()` is not so convenient as it makes you to do some pointer conversions. Fortunately there is another way to convert a pipe type: use functions from `pipe/prefixpipe.go`. These functions takes `Piper` or `PiperNoLen` as a first parameter and function to apply as the second and returns a resulting pipe (or the result itself) of a destination type. + +#### Prefix pipe functinos + +- :frog: `pipe.Map(Piper[SrcT], func(x SrcT) DstT) Piper[DstT] ` - applies *map* from one type to another for the `Pipe` with **known** length. +- :frog: `pipe.MapNL(PiperNoLen[SrcT], func(x SrcT) DstT) PiperNoLen[DstT] ` - applies *map* from one type to another for the `Pipe` with **unknown** length. +- :frog: `Reduce(Piper[SrcT], func(*DstT, *SrcT) DstT, initVal ...DstT)` - applies *reduce* operation on `Pipe` of type `SrcT` and returns result of type `DstT`. `initVal` is an optional parameter to **initialize** a value that should be used on the **first steps** of reduce. + +### Using `ff` package to write shortened pipes + +Sometimes you need just to apply a function. Creating a pipe using `pipe.Slice` and then call `Map` looks a little bit verbose, especially when you need to call `Map` or `Reduce` from one type to another. The solution for it is `funcfrog/pkg/ff` package. It contains shortened `Map` and `Reduce` functions which can be called directly with a slice as a first parameter. + +- :frog: `Map([]SrcT, func(SrcT) DstT) pipe.Piper[DstT]` - applies sent function to a slice, returns a `Pipe` of resulting type +- :frog: `Reduce([]SrcT, func(*DstT, *SrcT) DstT, initVal ...DstT) DstT` - applies *reduce* operation on a slice and returns the result of type `DstT`. `initVal` is an optional parameter to **initialize** a value that should be used on the **first steps** of reduce. + +### Look for useful functions in `Pipies` package + +Some of the functions that are sent to `Map`, `Filter` or `Reduce` (or other `Pipe` methods) are pretty common. Also there is a common comparator for any integers and floats for a `Sort` method. + ## Examples ### Basic example: diff --git a/coverage_badge.png b/coverage_badge.png index 30891f7b287d6f09903432c8264cfc35051e7fad..22cc9fa86f95bda5ea03a0dcbeeaed77517df700 100644 GIT binary patch literal 2483 zcmV;k2~75hP)2$s-rF>3Gd9U-Dw3q~a=N9msmi{2BX_^)HI-ALkNg((T zq+Fx^u#A6yOd7$#sZOF~?^{f!KAe!?ilU(FI)OldKp^nF0&1Fu!{Na1_Y)3>zZcj2 zg0cEg6)J`_kc{-vELKvjF1iNW37dlxw&_|L14i$t@`++h!L3#+<>lqfojaGVt}g6$ zJ5owco;=B^Q>X4IP<(tm<>lqfnKOs(?rt(NGPrc<5^uiwCY_y~ca{A8f>?c+sOs!1 zc#l7RTTN5{`Dpp0$xpCl>T7sI9@6669QgMZzUcY;xVGn~9zY|GEPEbrT(04~|1$t~ zOh3Y(TWe|TZx}b%F$LeWX%kXPDk>@ng+iF7NnTza#l^)V8mVa-x~}8(dSf^7GhGE3?6GGr{I1obM^Z7>cYnn!K zax$Hrog-`$;lEw3OI)id$=rZDZVHhBGwLG{{N}+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