Skip to content

Commit

Permalink
Merge pull request #2 from devalexandre/feat/update-go-version
Browse files Browse the repository at this point in the history
feat: update go version and update pipe function
  • Loading branch information
devalexandre authored Jul 24, 2024
2 parents 88e22b3 + cbd2910 commit 40996e0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ name: Go

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"

- name: Test
run: go test -v ./...
- name: Test
run: go test -v ./...
23 changes: 23 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: golangci-lint
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/devalexandre/pipe

go 1.20
go 1.22

require github.com/devalexandre/gofn v1.0.1 // indirect
require github.com/devalexandre/gofn v1.0.1
6 changes: 3 additions & 3 deletions v1/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type Pipeline func(...interface{}) (interface{}, error)
// Pipe creates a pipeline from a series of functions.
func Pipe(fs ...interface{}) Pipeline {
return func(initialArgs ...interface{}) (interface{}, error) {
var currentArgs []interface{} = initialArgs
currentArgs := initialArgs
for _, f := range fs {
fnVal := reflect.ValueOf(f)
fnType := fnVal.Type()
numIn := fnType.NumIn()

// Prepare the input arguments for the current function.
in := make([]reflect.Value, numIn)
for i := 0; i < numIn; i++ {
for i := range numIn {
if i < len(currentArgs) {
in[i] = reflect.ValueOf(currentArgs[i])
} else if i < len(initialArgs) { // Allow passing manual arguments if not enough currentArgs.
Expand All @@ -34,7 +34,7 @@ func Pipe(fs ...interface{}) Pipeline {
results := fnVal.Call(in)

// Assume the last function call results will be used as next input.
currentArgs = []interface{}{} // Reset currentArgs for next function.
currentArgs = nil // Reset currentArgs for next function.
for _, result := range results {
if result.Type().Implements(reflect.TypeOf((*error)(nil)).Elem()) {
if !result.IsNil() { // If the result is an error, return it.
Expand Down

0 comments on commit 40996e0

Please sign in to comment.