stream4

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 1 Imported by: 0

README

Stream4

Stream4 is a JAVA-stream-style Go library using generics, allows streaming operation with up to 4 types.

Quick Start

package main

import (
    "fmt"
    "github.com/Asterism12/stream4"
)

func main() {
	even := stream4.Slice([]int{1, 2, 3, 4, 5}).
		Filter(func(i int) bool {
			return i%2 == 0
		}).
		ToList()
	fmt.Println(even)
	// output : [2 4]

	acc := stream4.Slice2[int, float32]([]int{1, 2, 3, 4, 5}).
		Reduce2(func(v int, acc float32, i int) float32 {
			return acc + 0.1*float32(v)
		}, 0)
	fmt.Println(acc)
	// output : 1.5

	stream4.Slice3[int, float32, string]([]int{1, 2, 3}).
		Map2(func(v int) float32 {
			return float32(v) + 0.5
		}).
		Map(func(v float32) float32 {
			return v + 0.1
		}).
		Map3(func(v float32) string {
			return fmt.Sprintf("%f", v)
		}).
		ForEach(func(v string) {
			fmt.Printf("%s ", v)
		})
	// output : 1.600000 2.600000 3.600000

	min := stream4.Slice4[int, int, int, int]([]int{5, 4, 3, 2, 1}).
		Limit(3).
		Min(func(i int, j int) bool {
			return i < j
		})
	fmt.Println(min)
	// output : 3
}

Supported Operation

  • Map
  • Reduce
  • Filter
  • ForEach
  • Limit
  • Min
  • GroupBy(not streaming)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupBy

func GroupBy[K comparable, V any](vs []V, f func(v V) K) map[K][]V

GroupBy grouping elements according to a classification function, and returning the results in a Map

Types

type Stream1

type Stream1[T1 any, T2 any, T3 any, T4 any] struct {
	// contains filtered or unexported fields
}

Stream1 a sequence of elements of type 1

func Slice

func Slice[T any](vs []T) Stream1[T, any, any, any]

Slice returns a sequential Stream supporting 1 type with the specified slice as its source

func Slice2

func Slice2[T1 any, T2 any](vs []T1) Stream1[T1, T2, any, any]

Slice2 returns a sequential Stream supporting 2 types with the specified slice as its source

func Slice3

func Slice3[T1 any, T2 any, T3 any](vs []T1) Stream1[T1, T2, T3, any]

Slice3 returns a sequential Stream supporting 3 types with the specified slice as its source

func Slice4

func Slice4[T1 any, T2 any, T3 any, T4 any](vs []T1) Stream1[T1, T2, T3, T4]

Slice4 returns a sequential Stream supporting 4 types with the specified slice as its source

func (Stream1[T1, T2, T3, T4]) Filter

func (s Stream1[T1, T2, T3, T4]) Filter(f func(T1) bool) Stream1[T1, T2, T3, T4]

Filter returns the results of the elements of this slice that match the given predicate

func (Stream1[T1, T2, T3, T4]) ForEach

func (s Stream1[T1, T2, T3, T4]) ForEach(f func(T1))

ForEach performs an action for each element of this slice

func (Stream1[T1, T2, T3, T4]) Limit

func (s Stream1[T1, T2, T3, T4]) Limit(limit int) Stream1[T1, T2, T3, T4]

Limit returns the results of the elements of this slice, truncated to be no longer than maxSize in length

func (Stream1[T1, T2, T3, T4]) Map

func (s Stream1[T1, T2, T3, T4]) Map(f func(T1) T1) Stream1[T1, T2, T3, T4]

Map returns the results of applying the given function to the elements of this slice

func (Stream1[T1, T2, T3, T4]) Map1

func (s Stream1[T1, T2, T3, T4]) Map1(f func(T1) T1) Stream1[T1, T2, T3, T4]

Map1 returns the results of applying the given function to the elements of this slice

convert result to type 1

func (Stream1[T1, T2, T3, T4]) Map2

func (s Stream1[T1, T2, T3, T4]) Map2(f func(T1) T2) Stream2[T1, T2, T3, T4]

Map2 returns the results of applying the given function to the elements of this slice

convert result to type 2

func (Stream1[T1, T2, T3, T4]) Map3

func (s Stream1[T1, T2, T3, T4]) Map3(f func(T1) T3) Stream3[T1, T2, T3, T4]

Map3 returns the results of applying the given function to the elements of this slice

convert result to type 3

func (Stream1[T1, T2, T3, T4]) Map4

func (s Stream1[T1, T2, T3, T4]) Map4(f func(T1) T4) Stream4[T1, T2, T3, T4]

Map4 returns the results of applying the given function to the elements of this slice

convert result to type 4

func (Stream1[T1, T2, T3, T4]) Min

func (s Stream1[T1, T2, T3, T4]) Min(less func(T1, T1) bool) T1

Min returns the minimum element of this stream according to the provided less function

func (Stream1[T1, T2, T3, T4]) Reduce

func (s Stream1[T1, T2, T3, T4]) Reduce(f func(v T1, acc T1, i int) T1, initial T1) T1

Reduce performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

func (Stream1[T1, T2, T3, T4]) Reduce1

func (s Stream1[T1, T2, T3, T4]) Reduce1(f func(v T1, acc T1, i int) T1, initial T1) T1

Reduce1 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 1

func (Stream1[T1, T2, T3, T4]) Reduce2

func (s Stream1[T1, T2, T3, T4]) Reduce2(f func(v T1, acc T2, i int) T2, initial T2) T2

Reduce2 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 2

func (Stream1[T1, T2, T3, T4]) Reduce3

func (s Stream1[T1, T2, T3, T4]) Reduce3(f func(v T1, acc T3, i int) T3, initial T3) T3

Reduce3 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 3

func (Stream1[T1, T2, T3, T4]) Reduce4

func (s Stream1[T1, T2, T3, T4]) Reduce4(f func(v T1, acc T4, i int) T4, initial T4) T4

Reduce4 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 4

func (Stream1[T1, T2, T3, T4]) ToList

func (s Stream1[T1, T2, T3, T4]) ToList() []T1

ToList returns the slice

type Stream2

type Stream2[T1 any, T2 any, T3 any, T4 any] struct {
	// contains filtered or unexported fields
}

Stream2 a sequence of elements of type 2

func (Stream2[T1, T2, T3, T4]) Filter

func (s Stream2[T1, T2, T3, T4]) Filter(f func(T2) bool) Stream2[T1, T2, T3, T4]

Filter returns the results of the elements of this slice that match the given predicate

func (Stream2[T1, T2, T3, T4]) ForEach

func (s Stream2[T1, T2, T3, T4]) ForEach(f func(T2))

ForEach performs an action for each element of this slice

func (Stream2[T1, T2, T3, T4]) Limit

func (s Stream2[T1, T2, T3, T4]) Limit(limit int) Stream2[T1, T2, T3, T4]

Limit returns the results of the elements of this slice, truncated to be no longer than maxSize in length

func (Stream2[T1, T2, T3, T4]) Map

func (s Stream2[T1, T2, T3, T4]) Map(f func(T2) T2) Stream2[T1, T2, T3, T4]

Map returns the results of applying the given function to the elements of this slice

func (Stream2[T1, T2, T3, T4]) Map1

func (s Stream2[T1, T2, T3, T4]) Map1(f func(T2) T1) Stream1[T1, T2, T3, T4]

Map1 returns the results of applying the given function to the elements of this slice

convert result to type 1

func (Stream2[T1, T2, T3, T4]) Map2

func (s Stream2[T1, T2, T3, T4]) Map2(f func(T2) T2) Stream2[T1, T2, T3, T4]

Map2 returns the results of applying the given function to the elements of this slice

convert result to type 2

func (Stream2[T1, T2, T3, T4]) Map3

func (s Stream2[T1, T2, T3, T4]) Map3(f func(T2) T3) Stream3[T1, T2, T3, T4]

Map3 returns the results of applying the given function to the elements of this slice

convert result to type 3

func (Stream2[T1, T2, T3, T4]) Map4

func (s Stream2[T1, T2, T3, T4]) Map4(f func(T2) T4) Stream4[T1, T2, T3, T4]

Map4 returns the results of applying the given function to the elements of this slice

convert result to type 4

func (Stream2[T1, T2, T3, T4]) Min

func (s Stream2[T1, T2, T3, T4]) Min(less func(T2, T2) bool) T2

Min returns the minimum element of this stream according to the provided less function

func (Stream2[T1, T2, T3, T4]) Reduce

func (s Stream2[T1, T2, T3, T4]) Reduce(f func(v T2, acc T2, i int) T2, initial T2) T2

Reduce performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

func (Stream2[T1, T2, T3, T4]) Reduce1

func (s Stream2[T1, T2, T3, T4]) Reduce1(f func(v T2, acc T1, i int) T1, initial T1) T1

Reduce1 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 1

func (Stream2[T1, T2, T3, T4]) Reduce2

func (s Stream2[T1, T2, T3, T4]) Reduce2(f func(v T2, acc T2, i int) T2, initial T2) T2

Reduce2 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 2

func (Stream2[T1, T2, T3, T4]) Reduce3

func (s Stream2[T1, T2, T3, T4]) Reduce3(f func(v T2, acc T3, i int) T3, initial T3) T3

Reduce3 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 3

func (Stream2[T1, T2, T3, T4]) Reduce4

func (s Stream2[T1, T2, T3, T4]) Reduce4(f func(v T2, acc T4, i int) T4, initial T4) T4

Reduce4 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 4

func (Stream2[T1, T2, T3, T4]) ToList

func (s Stream2[T1, T2, T3, T4]) ToList() []T2

ToList returns the slice

type Stream3

type Stream3[T1 any, T2 any, T3 any, T4 any] struct {
	// contains filtered or unexported fields
}

Stream3 a sequence of elements of type 3

func (Stream3[T1, T2, T3, T4]) Filter

func (s Stream3[T1, T2, T3, T4]) Filter(f func(T3) bool) Stream3[T1, T2, T3, T4]

Filter returns the results of the elements of this slice that match the given predicate

func (Stream3[T1, T2, T3, T4]) ForEach

func (s Stream3[T1, T2, T3, T4]) ForEach(f func(T3))

ForEach performs an action for each element of this slice

func (Stream3[T1, T2, T3, T4]) Limit

func (s Stream3[T1, T2, T3, T4]) Limit(limit int) Stream3[T1, T2, T3, T4]

Limit returns the results of the elements of this slice, truncated to be no longer than maxSize in length

func (Stream3[T1, T2, T3, T4]) Map

func (s Stream3[T1, T2, T3, T4]) Map(f func(T3) T3) Stream3[T1, T2, T3, T4]

Map returns the results of applying the given function to the elements of this slice

func (Stream3[T1, T2, T3, T4]) Map1

func (s Stream3[T1, T2, T3, T4]) Map1(f func(T3) T1) Stream1[T1, T2, T3, T4]

Map1 returns the results of applying the given function to the elements of this slice

convert result to type 1

func (Stream3[T1, T2, T3, T4]) Map2

func (s Stream3[T1, T2, T3, T4]) Map2(f func(T3) T2) Stream2[T1, T2, T3, T4]

Map2 returns the results of applying the given function to the elements of this slice

convert result to type 2

func (Stream3[T1, T2, T3, T4]) Map3

func (s Stream3[T1, T2, T3, T4]) Map3(f func(T3) T3) Stream3[T1, T2, T3, T4]

Map3 returns the results of applying the given function to the elements of this slice

convert result to type 3

func (Stream3[T1, T2, T3, T4]) Map4

func (s Stream3[T1, T2, T3, T4]) Map4(f func(T3) T4) Stream4[T1, T2, T3, T4]

Map4 returns the results of applying the given function to the elements of this slice

convert result to type 4

func (Stream3[T1, T2, T3, T4]) Min

func (s Stream3[T1, T2, T3, T4]) Min(less func(T3, T3) bool) T3

Min returns the minimum element of this stream according to the provided less function

func (Stream3[T1, T2, T3, T4]) Reduce

func (s Stream3[T1, T2, T3, T4]) Reduce(f func(v T3, acc T3, i int) T3, initial T3) T3

Reduce performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

func (Stream3[T1, T2, T3, T4]) Reduce1

func (s Stream3[T1, T2, T3, T4]) Reduce1(f func(v T3, acc T1, i int) T1, initial T1) T1

Reduce1 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 1

func (Stream3[T1, T2, T3, T4]) Reduce2

func (s Stream3[T1, T2, T3, T4]) Reduce2(f func(v T3, acc T2, i int) T2, initial T2) T2

Reduce2 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 2

func (Stream3[T1, T2, T3, T4]) Reduce3

func (s Stream3[T1, T2, T3, T4]) Reduce3(f func(v T3, acc T3, i int) T3, initial T3) T3

Reduce3 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 3

func (Stream3[T1, T2, T3, T4]) Reduce4

func (s Stream3[T1, T2, T3, T4]) Reduce4(f func(v T3, acc T4, i int) T4, initial T4) T4

Reduce4 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 4

func (Stream3[T1, T2, T3, T4]) ToList

func (s Stream3[T1, T2, T3, T4]) ToList() []T3

ToList returns the slice

type Stream4

type Stream4[T1 any, T2 any, T3 any, T4 any] struct {
	// contains filtered or unexported fields
}

Stream4 a sequence of elements of type 4

func (Stream4[T1, T2, T3, T4]) Filter

func (s Stream4[T1, T2, T3, T4]) Filter(f func(T4) bool) Stream4[T1, T2, T3, T4]

Filter returns the results of the elements of this slice that match the given predicate

func (Stream4[T1, T2, T3, T4]) ForEach

func (s Stream4[T1, T2, T3, T4]) ForEach(f func(T4))

ForEach performs an action for each element of this slice

func (Stream4[T1, T2, T3, T4]) Limit

func (s Stream4[T1, T2, T3, T4]) Limit(limit int) Stream4[T1, T2, T3, T4]

Limit returns the results of the elements of this slice, truncated to be no longer than maxSize in length

func (Stream4[T1, T2, T3, T4]) Map

func (s Stream4[T1, T2, T3, T4]) Map(f func(T4) T4) Stream4[T1, T2, T3, T4]

Map returns the results of applying the given function to the elements of this slice

func (Stream4[T1, T2, T3, T4]) Map1

func (s Stream4[T1, T2, T3, T4]) Map1(f func(T4) T1) Stream1[T1, T2, T3, T4]

Map1 returns the results of applying the given function to the elements of this slice

convert result to type 1

func (Stream4[T1, T2, T3, T4]) Map2

func (s Stream4[T1, T2, T3, T4]) Map2(f func(T4) T2) Stream2[T1, T2, T3, T4]

Map2 returns the results of applying the given function to the elements of this slice

convert result to type 2

func (Stream4[T1, T2, T3, T4]) Map3

func (s Stream4[T1, T2, T3, T4]) Map3(f func(T4) T3) Stream3[T1, T2, T3, T4]

Map3 returns the results of applying the given function to the elements of this slice

convert result to type 3

func (Stream4[T1, T2, T3, T4]) Map4

func (s Stream4[T1, T2, T3, T4]) Map4(f func(T4) T4) Stream4[T1, T2, T3, T4]

Map4 returns the results of applying the given function to the elements of this slice

convert result to type 4

func (Stream4[T1, T2, T3, T4]) Min

func (s Stream4[T1, T2, T3, T4]) Min(less func(T4, T4) bool) T4

Min returns the minimum element of this stream according to the provided less function

func (Stream4[T1, T2, T3, T4]) Reduce

func (s Stream4[T1, T2, T3, T4]) Reduce(f func(v T4, acc T4, i int) T4, initial T4) T4

Reduce performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

func (Stream4[T1, T2, T3, T4]) Reduce1

func (s Stream4[T1, T2, T3, T4]) Reduce1(f func(v T4, acc T1, i int) T1, initial T1) T1

Reduce1 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 1

func (Stream4[T1, T2, T3, T4]) Reduce2

func (s Stream4[T1, T2, T3, T4]) Reduce2(f func(v T4, acc T2, i int) T2, initial T2) T2

Reduce2 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 2

func (Stream4[T1, T2, T3, T4]) Reduce3

func (s Stream4[T1, T2, T3, T4]) Reduce3(f func(v T4, acc T3, i int) T3, initial T3) T3

Reduce3 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 3

func (Stream4[T1, T2, T3, T4]) Reduce4

func (s Stream4[T1, T2, T3, T4]) Reduce4(f func(v T4, acc T4, i int) T4, initial T4) T4

Reduce4 performs a reduction on the elements of this slice, using the provided identity, accumulation and combining functions

convert result to type 4

func (Stream4[T1, T2, T3, T4]) ToList

func (s Stream4[T1, T2, T3, T4]) ToList() []T4

ToList returns the slice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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