Skip to content
/ pipe Public

Pipe is a clone of Clojure's Threading Macros concept.

License

Notifications You must be signed in to change notification settings

parinpan/pipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipe is a clone of Clojure's Threading Macros concept. It offers simplicity to construct a series of function executions in a syntactic sugar way.

Installation

go get -u github.com/parinpan/pipe

Usage

See the full example here: https://github.com/parinpan/pipe/blob/master/example/pipe_implementation.go

result := pipe.Do(
  pipe.Apply(funcA),
  pipe.Apply(funcB),
  pipe.Apply(funcC),
  pipe.Apply(funcD),
)

fmt.Printf("%+v\n", result)

// more advanced usage

result := pipe.Do(
  pipe.Apply(getRestaurants),
  pipe.Apply(getFoodsWithFilter, 10, pipe.Pass(), 5),
  pipe.Apply(getFoodPrices),
  pipe.Apply(getFoodTotalPriceText, pipe.Pass(func(prices []int) int {
    var totalPrice = 0

    for _, price := range prices {
      totalPrice += price
    }

    return totalPrice
  })))

fmt.Printf("%+v\n", result)