From 29c497e82e87deb42e9fd24372b449d40c9fc9c6 Mon Sep 17 00:00:00 2001 From: Dima Kossovich Date: Mon, 23 Sep 2024 14:56:08 +0300 Subject: [PATCH] removed outdated examples from README; removed outdated example folder --- README.md | 8 ++--- example/README.md | 3 -- example/main._go | 80 ----------------------------------------------- 3 files changed, 3 insertions(+), 88 deletions(-) delete mode 100644 example/README.md delete mode 100644 example/main._go diff --git a/README.md b/README.md index af3e7f9..04a1288 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ is better when multithreading). ## Table of Contents - [Getting Started](#getting-started) - [Basic information](#basic-information) -- [Supported functions list](#supported-functions-list) +- **[Supported functions list](#supported-functions-list)** - [Constructors](#constructors) - [Set Pipe length](#set-pipe-length) - [Split evaluation into *n* goroutines](#split-evaluation-into-n-goroutines) @@ -28,7 +28,7 @@ is better when multithreading). - [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) +- **[Examples](#examples)** - [Basic example](#basic-example) - [Example using `Func` and `Take`](#example-using-func-and-take) - [Example using `Func` and `Gen`](#example-using-func-and-gen) @@ -66,9 +66,7 @@ You can then use the `pipe` package to create a pipeline of operations on a slic ```go res := pipe.Slice(a). Map(func(x int) int { return x * x }). - Map(func(x int) int { return x + 1 }). Filter(func(x *int) bool { return *x > 100 }). - Filter(func(x *int) bool { return *x < 1000 }). Parallel(12). Do() ``` @@ -82,7 +80,7 @@ import "github.com/koss-null/funcfrog/pkg/ff" res := ff.Map(strArr, strings.ToUpper).Do() ``` -To see some code snippets, check out the `examples/main.go` file. You can also run it with `go run examples/main.go`. +To see some code snippets, check out the [Examples](#examples). ## Basic information diff --git a/example/README.md b/example/README.md deleted file mode 100644 index c29e222..0000000 --- a/example/README.md +++ /dev/null @@ -1,3 +0,0 @@ -This is an example package. It is not to be imported. -Feel free to run examples with `go run .../funcfrog/examples/main.go` and play along with them. -Also there are some performance testing. diff --git a/example/main._go b/example/main._go deleted file mode 100644 index 55fc9be..0000000 --- a/example/main._go +++ /dev/null @@ -1,80 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/koss-null/funcfrog/pkg/pipe" -) - -type DomObj struct{ i int } - -func GetUser(i int) (*DomObj, error) { - if i%2 != 0 { - return &DomObj{i}, nil - } - return nil, fmt.Errorf("%d user can't be found", i) -} - -func EnrichUser(do *DomObj) (*DomObj, error) { - if do.i%3 == 0 { - return nil, fmt.Errorf("user can't be enriched %d", do.i) - } - return do, nil -} - -type MyStruct struct{ Weight int } - -func main() { - p := pipe.Slice([]int{1, 2, 3}). - Erase(). - Map(func(x any) any { - i := *(x.(*int)) - return &MyStruct{Weight: i} - }).Filter(func(x *any) bool { - return (*x).(*MyStruct).Weight > 10 - }) - ms := pipe.Collect[MyStruct](p).Parallel(10).Do() - - getUserErr := make(chan error, 1) - handleGetUserErr := func(err error) { - getUserErr <- err - } - enrichUserErr := make(chan error, 1) - handleEnrichUserErr := func(err error) { - enrichUserErr <- err - } - go func() { - for err := range getUserErr { - fmt.Println("unable to get user", err) - } - }() - go func() { - for err := range enrichUserErr { - fmt.Println("unable to enrich user", err) - } - }() - - y1, y2 := pipe.NewYeti(), pipe.NewYeti() - users := pipe.Func(func(i int) (*DomObj, bool) { - domObj, err := GetUser(i) - if err != nil { - y1.Yeet(err) - return nil, false - } - return domObj, true - }).Yeti(y1). - Snag(handleGetUserErr). // suppose we have some pre-defined handler - MapFilter(func(do *DomObj) (*DomObj, bool) { - enriched, err := EnrichUser(do) - if err != nil { - y2.Yeet(err) - return nil, false - } - return enriched, true - }).Yeti(y2).Snag(handleEnrichUserErr). - Gen(20). - Parallel(16). - Do() - - fmt.Println(users) -}