Skip to content
main
Switch branches/tags
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

Callbag.go

this is an implementation for Callbag's base core functionality in Go using new generics feature in 1.18.

At the moment the following functions have been implemented

  • Interval
  • FromSlice
  • FromRange
  • FromChannel
  • Filter
  • Map
  • Reduce
  • Take
  • ForEach
  • Pipe

Installtion

go get github.com/alinz/callbag.go

Example

count all numbers from 0 to 10

package main

import (
	"fmt"
	"sync"

	"github.com/alinz/callbag.go"
)

func main() {
	var wg sync.WaitGroup

	wg.Add(1)

	src := callbag.FromRange(0, 11, 1) // range is [a, b), or upto 11

	sum := callbag.Reduce(func(base, value int) int {
		return base + value
	}, 0)

	sink := callbag.ForEach(func(value int, ok bool) {
		if !ok {
			wg.Done()
			return
		}

		fmt.Println("Result:", value)
	})

	callbag.Pipe3(src, sum, sink)

	wg.Wait()
}

About

golang implementation of Callbag

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages