Skip to content

A Java like stream API written in Go.

License

Notifications You must be signed in to change notification settings

SimpleDays/gostream

 
 

Repository files navigation

GOSTREAM

Gostream is a Java like stream API written in Go. It support functional-style operations on streams of elements, such as map-reduce transformations on collections.

Build Status codecov GoDoc Go Report Card

Installation

  1. The first need Go installed (version 1.14+ is required), then you can use the below Go command to install Gostream.
$ go get github.com/gaojunhuicavon/gostream
  1. Import it in your code:
import "github.com/gaojunhuicavon/gostream"

Example

package main

import (
	"github.com/gaojunhuicavon/gostream"
	"log"
)

const (
	red color = iota
	green
	yellow
)

type color int

type widget struct {
	color  color
	weight int
}

func main() {
	widgets := []*widget{{red, 1}, {green, 2}, {yellow, 3}}
	max, err := gostream.NewSequentialStream(widgets).Filter(func(val interface{}) (match bool) {
		return val.(*widget).color == red
	}).MapToInt(func(src interface{}) (dest int) {
		return src.(*widget).weight
    }).Max()
	if err != nil {
		log.Printf("get an error: %s\n", err.Error())
		return
	}
	if max != nil {
		log.Printf("the max weight is %d\n", *max)
	}
}

About

A Java like stream API written in Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%