Skip to content

Commit

Permalink
Fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianrob committed Jul 14, 2019
1 parent 545422b commit 9b9af2c
Showing 1 changed file with 37 additions and 56 deletions.
93 changes: 37 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,50 @@ With this package, you can chain a series of functions to build a pipeline

### Example 1

```
```go
import (
"fmt"
"thennable"
"fmt"
"thennable"
)

func AddOne(num int) (int, error) {
return num + 1, nil
return num + 1, nil
}

func Decide(num int) (string, error) {
if num == 1 {
return "one"
if num == 1 {
return "one"
else {
return "not one"
}
return "not one"
}
}

func main() {
result, err := thennable.Start(0). //start with zero
Then(AddOne). //0+1
result, err := thennable.Start(0). //start with zero
Then(AddOne). //0+1
Then(Decide). //1 = one
End()
str := result[0].(string)
str := result[0].(string)
fmt.Printf("Res: %v, Str: %s, Err: %v", result, str, err)
//Res: [one], Str: one, Err: <nil>
}
```

### Example 2: Inlining
```
```go
import (
"fmt"
"thennable"
"fmt"
"thennable"
)

func main() {
result, err := thennable.Start(1). //start with 1
Then(func (one int) (int, int, error) {
return one, 2, nil
result, err := thennable.Start(1). //start with 1
Then(func (one int) (int, int, error) {
return one, 2, nil
}). //return 1, 2
Then(func (one, two int) (int, int, int, error) {
return one, two, 3, nil
return one, two, 3, nil
}) //return 1, 2, 3
End()
fmt.Printf("Res: %v, Str: %s, Err: %v", result, str, err)
Expand All @@ -57,53 +56,55 @@ func main() {
```
### Example 3: Error Occurred
```
```go
import (
"fmt"
"fmt"
"errors"
"thennable"
"thennable"
)

func AddOne(num int) (int, error) {
return num + 1, nil
return num + 1, nil
}

func main() {
result, err := thennable.Start(1). //start with 1
Then(AddOne). //1 + 1
result, err := thennable.Start(1). //start with 1
Then(AddOne). //1 + 1
Then(func (two int) (int, error) {
return two, errors.New("Whooops, something happened")
return two, errors.New("Whooops, something happened")
}). //return 2, error
Then(AddOne). //skipped
Then(AddOne). //skipped
End()

fmt.Printf("Res: %v, Str: %s, Err: %v", result, str, err)
//Res: [2], Err: Whooops, something happened
}
```
### Example 4: Recover from error
```
```go
import (
"fmt"
"fmt"
"errors"
"thennable"
"thennable"
)

func AddOne(num int) (int, error) {
return num + 1, nil
return num + 1, nil
}

func main() {
result, err := thennable.Start(1). //start with 1
result, err := thennable.Start(1). //start with 1
BreakOnError(false). //Pipeline keeps going when error happens
Then(AddOne). //1 + 1
Then(AddOne). //1 + 1
Then(func (two int) error {
return errors.New("Whooops, something happened")
}). //return error
Supply(8) //resuply the pipeline with 8
return errors.New("Whooops, something happened")
}). //return error
Supply(8) //resuply the pipeline with 8
Then(AddOne). //8 + 1
Then(AddOne). //9 + 1
End()
Expand All @@ -113,23 +114,3 @@ func main() {
}
```




















0 comments on commit 9b9af2c

Please sign in to comment.