GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Morgahl/pipe

BranchesTags
Open more actions menu

Latest commit

 

History

65 Commits
65 Commits

Folders and files

NameName
Last commit message
Last commit date
example/dir_scan
example/dir_scan
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
doc.go
doc.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
head.go
head.go
 
 
head_test.go
head_test.go
 
 
tail.go
tail.go
 
 
tail_test.go
tail_test.go
 
 
util.go
util.go
 
 
workers.go
workers.go
 
 

Repository files navigation

Pipe - Type Safe Functional Channels

This library melds functional programming paradigms and common Go function call patterns over top of Go's channels in a type safe manner. A channel is split into its Head[T] (push only) and Tail[T] (pull only) ends. Tail[T] carries the functional operations such as Filter, Map, and Reduce, with Error and ErrorSink variants for functions that can fail and Async variants such as MapAsync that run a function across a pool of workers at the cost of ordering. Source builds a Tail[T] from a function and calls a closer when the function is exhausted or returns Done. Every operation manages the lifecycle of the channels and goroutines it creates, so the library user never closes a channel they did not make.

Requires Go 1.27 for parameterized methods.

Dependencies

This library imports only the standard library and has no 3rd party dependencies. The goal is to maintain this always for produciton code. The exception being importing 3rd party libraries for testing purposes only.

Usage

head, tail := pipe.New[int](16)

go func() {
    defer head.Close()
    for i := 0; i < 100; i++ {
        head.Push(i)
    }
}()

sum := tail.
    Filter(func(i int) bool { return i%2 == 0 }).
    Map(func(i int) int { return i * i }).
    Reduce(0, func(i, acc int) int { return acc + i })

Each Tail[T] method returns a new Tail[T] (or a value for the blocking operations Reduce, Sink, Drain, Wait) and closes what it returns after its input is closed and emptied. Chains read top to bottom in the order values flow. An operation handed an input it cannot use, such as a nil Tail[T] or a nil function, panics at the call rather than in a worker goroutine; the package documentation lists every case.

Examples

The example folder contains functional, if sometimes contrived, example implementations of library functionality. example/dir_scan walks a directory, hashes every file across a pool of goroutines, and reports throughput in one-second windows.

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.