Stream [WIP]

Build
codecov

Introduction

Stream is a stream library based on golang 1.18 generics, support parallel. (manipulate slice like java stream)

Getting Started

Basic

s := stream.NewSliceByOrdered([]string{"d", "a", "b", "c", "a"}).
    Filter(func(s string) bool { return s != "b" }).
    Map(func(s string) string { return "class_" + s }).
    Sort().
    Distinct().
    ToSlice()

Constraints

// any
stream.NewSlice([]int{1, 2, 3, 7, 1})

// comparable
stream.NewSliceByComparable([]int{1, 2, 3, 7, 1})

// constraints.Ordered
stream.NewSliceByComparable([]int{1, 2, 3, 7, 1})

Parallel

s4 := stream.NewSliceByOrdered([]string{"d", "a", "b", "c", "a"}).
    Parallel(10).
    Filter(func(s string) bool { return s != "b" }).
    Map(func(s string) string { return "class_" + s }).
    Sort().
    Distinct().
    ToSlice()

GitHub

View Github