pipeline

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2023 License: MIT Imports: 0 Imported by: 0

README

Pipeline GoDoc Build Status Coverage Status Go Report Card

Go pipeline solution that can be used in many different combinations for chaining pipeline steps.

Inspired by @bilal-kilic's Kotlin implementation boru.

Usage

Supports 1.18+ Go versions because of Go Generics

go get github.com/mhmtszr/pipeline
Examples
package main

import (
	"fmt"
	"github.com/mhmtszr/pipeline"
)

type Square struct{}
type Add struct{}

func (s Square) Execute(context int, next func(context int)) {
	context = context * context
	println(fmt.Sprintf("After first chain context: %d", context))
	next(context)
}

func (a Add) Execute(context int, next func(context int)) {
	context = context + context
	println(fmt.Sprintf("After second chain context: %d", context))
	next(context)
}

func main() {
	p := pipeline.Builder[int]{}.UsePipelineStep(Square{}).UsePipelineStep(Add{}).Build()
	p.Execute(3)
}
// After first chain context: 9
// After second chain context: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder[K any] struct {
	// contains filtered or unexported fields
}

func (Builder[K]) Build added in v0.0.3

func (t Builder[K]) Build() Pipeline[K]

func (Builder[K]) UsePipelineStep added in v0.0.3

func (t Builder[K]) UsePipelineStep(step Step[K]) Builder[K]

type Pipeline

type Pipeline[K any] struct {
	// contains filtered or unexported fields
}

func (Pipeline[K]) Execute added in v0.0.3

func (t Pipeline[K]) Execute(context K)

type Step

type Step[K any] interface {
	Execute(context K, next func(context K))
}

type StepDelegate

type StepDelegate[K any] func(context K)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL