creek

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: MIT Imports: 9 Imported by: 0

README

Creek Logo
Creek is a fully-featured Streams library for Go.
Creek creates wrappers around a specific data source (array or slice), allowing us to operate with that data source and making bulk processing convenient and fast. Creek helps you to follow the functional programming paradigms. It's not just a Streams library, you can work with arrays and slices more easily than ever.


Table of Contents


Why creek?

If you've always missed the functional programming paradigms from Golang, or ever wanted to work with streams in Go, this library will totally fit your needs.
If you are from a C# or a Java background, working with this library going to be easy since creek is very similar to Linq or the Java Streams API.
Even if you just want to work with slices and arrays more conveniently and easily, but don't like functional programming, you can do that too.


Installation

Before installing this library, you need to have Go installed.

Since creek uses generics, version 1.18+ is required.

Now, you can initialize a project and use this library:

go get -u github.com/0l1v3rr/creek

Quick start

package main

import (
    "fmt"

    "github.com/0l1v3rr/creek"
)

func main() {
    arr := []int{1, 8, 2, 14, 22, 4, 7, 92}

    result := creek.FromArray(arr).Filter(func(item int) bool {
        return item > 3
    }).OrderBy().Collect()

    fmt.Println(result) // [4 7 8 14 22 92]
}

Create stream

You can create a stream from almost every type of array or slice.

Stream from primitive types

There are 53 functions you can use with this type of stream. (E.g: Filter, Map, OrderBy, etc..).
You can find them documented here.

Important: The functions do not modify the original array or the previous stream. Most of the functions return a new stream.

The supported types are the following:

string, byte, float32, float64, int, int16, int32, int64, uint16, uint32, uint64
// --== Create an empty stream ==--
emptyStream := creek.Empty[int]()
// --== Stream from an existing array or slice ==--

// slice
arr := []int{1, 8, 2, 14, 22, 4, 7, 92}
intStream := creek.FromArray(arr)

// array
arr2 := [3]string{"One", "Two", "Three"}
stringStream := creek.FromArray(arr2[:])
// --== Stream from parameter values ==--
stream := creek.FromValues("Apple", "Strawberry", "Peach")
// --== Stream from a file ==--
// The file is read line by line. Each line is an element of the stream.
file, _ := os.Open("/path/to/file.txt")
stream := creek.FromFile(file)
Stream from struct arrays

The FromStruct function creates a new stream from the given struct array.
If the given array is not made of struct, it throws an error.

There are 49 functions you can use with this type of stream. (E.g: Filter, Map, OrderBy, etc..).
You can find them documented here.

Important: The functions do not modify the original array or the previous stream. Most of the functions return a new stream.

type YourStruct struct {
	Id   int64
	Name string
}

func yourFunction() {
	structArray := []YourStruct{
		{Id: 1, Name: "John"},
		{Id: 2, Name: "Will"},
		{Id: 3, Name: "Mark"},
	}

	structStream := creek.FromStructs(structArray)
}

If you use this stream, there are some functions, where you need to pass the name of the field in order to work. These functions are the following:
Average, Max, MaxIndex, Min, MinIndex, OrderBy, OrderByDescending, Sum.
For example:

structArray := []YourStruct{
    {Id: 1, Name: "John"},
    {Id: 2, Name: "Will"},
    {Id: 3, Name: "Mark"},
}

// The functions are case sensitive. 'name', 'nAme', or 'nAMe' won't work.
// Make sure you spell it correctly, otherwise it throws an error.
structStream := creek.FromStructs(structArray).OrderBy("Name")
Create stream from maps

There are 37 functions you can use with this type of stream.
You can find them documented here.

Important: The functions do not modify the original array or the previous stream. Most of the functions return a new stream.

The supported key and value types are the following:

string, byte, float32, float64, int, int16, int32, int64, uint16, uint32, uint64
// --== Stream from an existing map ==--
arr := map[int]string{
    1: "Mark",
    2: "John",
    3: "Jack",
}

stream := creek.FromMap(arr)
// --== Create an empty stream ==--
// [key, value]
empty := creek.EmptyMap[int, string]()

Method chaining

With creek, method chaining is very straightforward and easy to read.
This code below:

  • filters the array, so only the even numbers stay
  • multiplies every number by 3
  • sorts the array in descending order
  • constrains the array to the length of 5
  • collects the array from the stream
arr := []int{2, 7, 3, 1, 12, 6, 82, 101, 23, 24, 72, 13, 7}

result := creek.FromArray(arr).Filter(func(item int) bool {
    return item%2 == 0
}).Map(func(item int) int {
    return item * 3
}).OrderByDescending().Limit(5).Collect()

// result: [246, 216, 72, 36, 18]

Download and build from source

Cloning the repository:

https://github.com/0l1v3rr/creek.git
cd creek
  • Running the tests: make test
  • Running the test in detailed version: make test_detailed
  • Test coverage: make test_coverage
  • Go formatting: make fmt
  • Docs: make docs
  • Go vet: make vet

Creek VS Linq VS Java Streams API

Creek is quite similar compared to these libraries.
Here you can see the similarities between Creek, Linq, and Java Streams API.
The expected output is the following:

4
8
12
16
Linq
List<int> list = new List<int>{ 1, 7, 2, 5, 9, 6, 3, 4, 8 };
var result = list
    .Where(num => num % 2 == 0)
    .Select(num => num * 2)
    .OrderBy(num => num)
    .ToList();

result.ForEach(num => Console.WriteLine(num));
Java Streams API
List<Integer> list = List.of(1, 7, 2, 5, 9, 6, 3, 4, 8);
List<Integer> result = list
        .stream()
        .filter(num -> num % 2 == 0)
        .map(num -> num * 2)
        .sorted()
        .toList();

result.forEach(System.out::println);
Creek
list := creek.FromValues(1, 7, 2, 5, 9, 6, 3, 4, 8)
result := list.Filter(func(num int) bool {
    return num%2 == 0
}).Map(func(num int) int {
    return num * 2
}).OrderBy().Collect()

creek.FromArray(result).ForEach(func(num int) {
    fmt.Println(num)
})

Contributing

Every contribution is welcomed.
You can find here a contributing guideline.


License

This project is licensed under the MIT License.

Documentation

Index

Constants

View Source
const ByKey bool = true
View Source
const ByValue bool = false

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyValuePair added in v1.3.0

type KeyValuePair[T Streamable, V Streamable] struct {
	Key   T
	Value V
}

type MapStream added in v1.3.0

type MapStream[T Streamable, V Streamable] struct {
	Array []KeyValuePair[T, V]
}

func EmptyMap added in v1.3.0

func EmptyMap[T Streamable, V Streamable]() MapStream[T, V]

The EmptyMap function creates a new empty stream for maps.

func FromMap added in v1.3.0

func FromMap[T Streamable, V Streamable](m map[T]V) MapStream[T, V]

The FromMap function creates a new stream from the given map.

func (MapStream[T, V]) All added in v1.3.0

func (s MapStream[T, V]) All(expression func(KeyValuePair[T, V]) bool) bool

The All function determines whether all elements of the stream satisfy the passed condition.

func (MapStream[T, V]) Append added in v1.3.0

func (s MapStream[T, V]) Append(item KeyValuePair[T, V]) MapStream[T, V]

The Append function adds an element to the stream.

func (MapStream[T, V]) AppendIf added in v1.3.0

func (s MapStream[T, V]) AppendIf(item KeyValuePair[T, V], c bool) MapStream[T, V]

The AppendIf function adds an element to the stream if the second parameter is true.

func (MapStream[T, V]) Average added in v1.3.0

func (s MapStream[T, V]) Average(byKey bool) float64

The Average function calculates the average of the stream. This function doesn't work with strings.

func (MapStream[T, V]) Bind added in v1.3.1

func (s MapStream[T, V]) Bind(v *map[T]V)

The Bind function binds the stream into the passed variable.

func (MapStream[T, V]) Clear added in v1.3.0

func (s MapStream[T, V]) Clear() Stream[T]

The Clear function clears every element from the stream.

func (MapStream[T, V]) Collect added in v1.3.0

func (s MapStream[T, V]) Collect() map[T]V

The Collect function returns the modified map from the streams.

func (MapStream[T, V]) ContainsKey added in v1.3.0

func (s MapStream[T, V]) ContainsKey(key T) bool

The ContainsKey function checks whether the stream contains an item with the passed key.

func (MapStream[T, V]) Count added in v1.3.0

func (s MapStream[T, V]) Count() int

The Count function returns the count of elements in the stream.

func (MapStream[T, V]) ElementAt added in v1.3.0

func (s MapStream[T, V]) ElementAt(index int) KeyValuePair[T, V]

The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it throws a panic.

func (MapStream[T, V]) ElementAtOrElse added in v1.3.0

func (s MapStream[T, V]) ElementAtOrElse(index int, elseValue KeyValuePair[T, V]) KeyValuePair[T, V]

The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it returns the elseValue, which is the second parameter.

func (MapStream[T, V]) Filter added in v1.3.0

func (s MapStream[T, V]) Filter(expression func(KeyValuePair[T, V]) bool) MapStream[T, V]

The Filter function leaves only those elements in the array that make the specified condition true.

func (MapStream[T, V]) Find added in v1.3.0

func (s MapStream[T, V]) Find(expression func(item KeyValuePair[T, V]) bool) KeyValuePair[T, V]

The Find function searches for an element that matches the conditions passed and returns the first occurrence within the entire stream.

func (MapStream[T, V]) FindIndex added in v1.3.0

func (s MapStream[T, V]) FindIndex(expression func(item KeyValuePair[T, V]) bool) int

The FindIndex function searches for an element that matches the conditions passed and returns the index of the first occurrence within the entire stream.

func (MapStream[T, V]) FindLast added in v1.3.0

func (s MapStream[T, V]) FindLast(expression func(item KeyValuePair[T, V]) bool) KeyValuePair[T, V]

The FindLast function searches for an element that matches the conditions passed and returns the last occurrence within the entire stream.

func (MapStream[T, V]) FindLastIndex added in v1.3.0

func (s MapStream[T, V]) FindLastIndex(expression func(item KeyValuePair[T, V]) bool) int

The FindLastIndex function searches for an element that matches the conditions passed and returns the index of the last occurrence within the entire stream.

func (MapStream[T, V]) First added in v1.3.0

func (s MapStream[T, V]) First() KeyValuePair[T, V]

The First method returns the first element in the stream.

func (MapStream[T, V]) ForEach added in v1.3.0

func (s MapStream[T, V]) ForEach(expression func(KeyValuePair[T, V]))

The ForEach method runs the specified method with every element in the Stream.

func (MapStream[T, V]) IsEmpty added in v1.3.0

func (s MapStream[T, V]) IsEmpty() bool

The IsEmpty function checks whether the stream is empty.

func (MapStream[T, V]) IsNotEmpty added in v1.3.0

func (s MapStream[T, V]) IsNotEmpty() bool

The IsNotEmpty function checks whether the stream is not empty.

func (MapStream[T, V]) Keys added in v1.3.2

func (s MapStream[T, V]) Keys() Stream[T]

The Keys function returns a new stream of the keys of the map.

func (MapStream[T, V]) Last added in v1.3.0

func (s MapStream[T, V]) Last() KeyValuePair[T, V]

The Last method returns the last element in the stream.

func (MapStream[T, V]) Map added in v1.3.0

func (s MapStream[T, V]) Map(expression func(item KeyValuePair[T, V]) KeyValuePair[T, V]) MapStream[T, V]

The Map function creates a new stream populated with the results of calling the provided function on every element.

func (MapStream[T, V]) Max added in v1.3.0

func (s MapStream[T, V]) Max(byKey bool) KeyValuePair[T, V]

The Max function returns the largest element from the stream.

func (MapStream[T, V]) MaxIndex added in v1.3.0

func (s MapStream[T, V]) MaxIndex(byKey bool) int

The MaxIndex function returns the index of the largest element from the stream.

func (MapStream[T, V]) Min added in v1.3.0

func (s MapStream[T, V]) Min(byKey bool) KeyValuePair[T, V]

The Min function returns the smallest element from the stream.

func (MapStream[T, V]) MinIndex added in v1.3.0

func (s MapStream[T, V]) MinIndex(byKey bool) int

The MinIndex function returns the index of the smallest element from the stream.

func (MapStream[T, V]) OrderBy added in v1.3.0

func (s MapStream[T, V]) OrderBy(byKey bool) MapStream[T, V]

The OrderBy function sorts the stream in ascending order.

func (MapStream[T, V]) OrderByDescending added in v1.3.0

func (s MapStream[T, V]) OrderByDescending(byKey bool) MapStream[T, V]

The OrderByDescending function sorts the stream in descending order.

func (MapStream[T, V]) RemoveKey added in v1.3.0

func (s MapStream[T, V]) RemoveKey(key T) MapStream[T, V]

The RemoveKey function removes every element from a stream where the key is equal to the passed item.

func (MapStream[T, V]) RemoveValue added in v1.3.0

func (s MapStream[T, V]) RemoveValue(value V) MapStream[T, V]

The RemoveValue function removes every element from a stream where the value is equal to the passed item.

func (MapStream[T, V]) RemoveWhere added in v1.3.0

func (s MapStream[T, V]) RemoveWhere(expression func(KeyValuePair[T, V]) bool) MapStream[T, V]

The RemoveWhere function removes all the entries that satisfy the provided condition.

func (MapStream[T, V]) Shuffle added in v1.3.0

func (s MapStream[T, V]) Shuffle() MapStream[T, V]

The Shuffle function shuffles the stream.

func (MapStream[T, V]) Some added in v1.3.0

func (s MapStream[T, V]) Some(expression func(item KeyValuePair[T, V]) bool) bool

The Some function determines whether any of the elements of the stream satisfy the passed condition.

func (MapStream[T, V]) Sum added in v1.3.0

func (s MapStream[T, V]) Sum(byKey bool) interface{}

The Sum function adds up all values in a stream.

func (MapStream[T, V]) Values added in v1.3.2

func (s MapStream[T, V]) Values() Stream[V]

The Values function returns a new stream of the values of the map.

func (MapStream[T, V]) Wait added in v1.3.0

func (s MapStream[T, V]) Wait(duration time.Duration) MapStream[T, V]

The Wait function pauses the current stream for the duration passed. The first and only parameter expects a value from the built-in time.Duration package.

type Stream

type Stream[T Streamable] struct {
	Array []T
}

func Empty added in v1.1.0

func Empty[T Streamable]() Stream[T]

The Empty function returns an empty stream.

func FromArray

func FromArray[T Streamable](array []T) Stream[T]

The FromArray function creates a new stream from the given array.

func FromFile added in v1.2.0

func FromFile(file *os.File) Stream[string]

The FromFile function creates a stream from a file. The file is read line by line. Each line is an element of the stream.

func FromValues added in v1.1.0

func FromValues[T Streamable](values ...T) Stream[T]

The FromValues function returns a stream made of the specified parameters.

func (Stream[T]) All added in v1.1.0

func (s Stream[T]) All(expression func(T) bool) bool

The All function determines whether all elements of the stream satisfy the passed condition.

func (Stream[T]) Append

func (s Stream[T]) Append(item T) Stream[T]

The Append function adds an element to the stream.

func (Stream[T]) AppendAt

func (s Stream[T]) AppendAt(index int, item T) Stream[T]

The AppendAt function inserts the specified element at the specified position in the stream.

func (Stream[T]) AppendIf added in v1.1.0

func (s Stream[T]) AppendIf(item T, c bool) Stream[T]

The AppendIf function adds an element to the stream if the second parameter is true.

func (Stream[T]) ArrEquals added in v1.1.0

func (s Stream[T]) ArrEquals(arr []T) bool

The ArrEquals function compares the stream and the passed array and returns true if they're equals.

func (Stream[T]) Average added in v1.1.0

func (s Stream[T]) Average() float64

The Average function calculates the average of the stream. This function doesn't work with strings.

func (Stream[T]) BinarySearch added in v1.2.3

func (s Stream[T]) BinarySearch(item T) int

The BinarySearch function finds the index of a target value within a sorted stream.

func (Stream[T]) Bind added in v1.3.1

func (s Stream[T]) Bind(v *[]T)

The Bind function binds the stream into the passed variable.

func (Stream[T]) Clear

func (s Stream[T]) Clear() Stream[T]

The Clear function clears every element from the stream.

func (Stream[T]) Collect

func (s Stream[T]) Collect() []T

The Collect function returns the modified array from the streams.

func (Stream[T]) Contains

func (s Stream[T]) Contains(item T) bool

The Contains function checks whether the stream contains the passed item.

func (Stream[T]) Count

func (s Stream[T]) Count() int

The Count function returns the count of elements in the stream.

func (Stream[T]) Distinct added in v1.1.0

func (s Stream[T]) Distinct() Stream[T]

The Distinct function filters every distinct element from the stream.

func (Stream[T]) ElementAt added in v1.1.0

func (s Stream[T]) ElementAt(index int) T

The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it throws a panic.

func (Stream[T]) ElementAtOrElse added in v1.1.0

func (s Stream[T]) ElementAtOrElse(index int, elseValue T) T

The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it returns the elseValue, which is the second parameter.

func (Stream[T]) Equals added in v1.1.0

func (s Stream[T]) Equals(b Stream[T]) bool

The Equals function compares two streams and returns true if they're equals.

func (Stream[T]) Filter

func (s Stream[T]) Filter(expression func(item T) bool) Stream[T]

The Filter function leaves only those elements in the array that make the specified condition true.

func (Stream[T]) Find added in v1.1.0

func (s Stream[T]) Find(expression func(item T) bool) T

The Find function searches for an element that matches the conditions passed and returns the first occurrence within the entire stream.

func (Stream[T]) FindIndex added in v1.1.0

func (s Stream[T]) FindIndex(expression func(item T) bool) int

The FindIndex function searches for an element that matches the conditions passed and returns the index of the first occurrence within the entire stream.

func (Stream[T]) FindLast added in v1.1.0

func (s Stream[T]) FindLast(expression func(item T) bool) T

The FindLast function searches for an element that matches the conditions passed and returns the last occurrence within the entire stream.

func (Stream[T]) FindLastIndex added in v1.1.0

func (s Stream[T]) FindLastIndex(expression func(item T) bool) int

The FindLastIndex function searches for an element that matches the conditions passed and returns the index of the last occurrence within the entire stream.

func (Stream[T]) First added in v1.2.1

func (s Stream[T]) First() T

The First method returns the first element in the stream.

func (Stream[T]) ForEach

func (s Stream[T]) ForEach(expression func(item T))

The ForEach method runs the specified method with every element in the Stream.

func (Stream[T]) IndexOf added in v1.1.0

func (s Stream[T]) IndexOf(item T) int

The IndexOf function returns the position of the first occurrence of the passed value in a stream.

func (Stream[T]) IsEmpty

func (s Stream[T]) IsEmpty() bool

The IsEmpty function checks whether the stream is empty.

func (Stream[T]) IsNotEmpty added in v1.2.1

func (s Stream[T]) IsNotEmpty() bool

The IsNotEmpty function checks whether the stream is not empty.

func (Stream[T]) Join

func (s Stream[T]) Join(separator string) string

Join concatenates the elements of the stream to create a single string. The passed parameter is placed between the elements.

func (Stream[T]) Last added in v1.2.1

func (s Stream[T]) Last() T

The Last method returns the last element in the stream.

func (Stream[T]) LastIndexOf added in v1.1.0

func (s Stream[T]) LastIndexOf(item T) int

The LastIndexOf function returns the position of the last occurrence of the passed value in a stream.

func (Stream[T]) Limit

func (s Stream[T]) Limit(amount int) Stream[T]

The Limit function constrains the number of elements returned by the stream.

func (Stream[T]) Map

func (s Stream[T]) Map(expression func(item T) T) Stream[T]

The Map function creates a new stream populated with the results of calling the provided function on every element.

func (Stream[T]) Max added in v1.1.0

func (s Stream[T]) Max() T

The Max function returns the largest element from the stream.

func (Stream[T]) MaxIndex added in v1.1.0

func (s Stream[T]) MaxIndex() int

The MaxIndex function returns the index of the largest element from the stream.

func (Stream[T]) Min added in v1.1.0

func (s Stream[T]) Min() T

The Min function returns the smallest element from the stream.

func (Stream[T]) MinIndex added in v1.1.0

func (s Stream[T]) MinIndex() int

The MinIndex function returns the index of the smallest element from the stream.

func (Stream[T]) OrderBy

func (s Stream[T]) OrderBy() Stream[T]

The OrderBy function sorts the stream in ascending order.

func (Stream[T]) OrderByDescending

func (s Stream[T]) OrderByDescending() Stream[T]

The OrderByDescending function sorts the stream in descending order.

func (Stream[T]) Push added in v1.2.3

func (s Stream[T]) Push(arr []T) Stream[T]

The Push function adds the passed array to the end of the stream.

func (Stream[T]) PushValues added in v1.2.3

func (s Stream[T]) PushValues(values ...T) Stream[T]

The PushValues function adds the passed values to the end of the stream.

func (Stream[T]) Remove

func (s Stream[T]) Remove(item T) Stream[T]

The Remove function removes the passed element from a stream.

func (Stream[T]) RemoveAt

func (s Stream[T]) RemoveAt(index int) Stream[T]

The RemoveAt function removes the item if its index matches the index passed in.

func (Stream[T]) RemoveDuplicates

func (s Stream[T]) RemoveDuplicates() Stream[T]

The RemoveDuplicates function removes every duplicate item from the stream.

func (Stream[T]) RemoveIf added in v1.1.0

func (s Stream[T]) RemoveIf(item T, c bool) Stream[T]

The RemoveIf function removes the passed element from a stream if the second parameter is true.

func (Stream[T]) RemoveWhere

func (s Stream[T]) RemoveWhere(expression func(item T) bool) Stream[T]

The RemoveWhere function removes all the entries that satisfy the provided condition.

func (Stream[T]) Replace added in v1.2.2

func (s Stream[T]) Replace(from T, to T) Stream[T]

The Replace function replaces every occurrence of 'from' to 'to'. The first parameter is 'from', and the second is 'to'.

func (Stream[T]) ReplaceWhere added in v1.2.2

func (s Stream[T]) ReplaceWhere(function func(item T) bool, to T) Stream[T]

The ReplaceWhere function replaces every element that satisfies the condition.

func (Stream[T]) Reverse

func (s Stream[T]) Reverse() Stream[T]

The Reverse function reverses the stream.

func (Stream[T]) Shuffle added in v1.2.1

func (s Stream[T]) Shuffle() Stream[T]

The Shuffle function shuffles the stream.

func (Stream[T]) Skip added in v1.3.1

func (s Stream[T]) Skip(amount int) Stream[T]

The Skip function discards the first n elements of a stream, where n is the passed parameter.

func (Stream[T]) Slice added in v1.2.2

func (s Stream[T]) Slice(start int, end int) Stream[T]

The Slice function returns a copy of a portion of a stream into a new stream selected from start to end (end not included) where start and end represent the index of items in the stream.

func (Stream[T]) Some added in v1.1.0

func (s Stream[T]) Some(expression func(item T) bool) bool

The Some function determines whether any of the elements of the stream satisfy the passed condition.

func (Stream[T]) Sum added in v1.1.0

func (s Stream[T]) Sum() T

The Sum function adds up all values in a stream.

func (Stream[T]) Wait added in v1.1.0

func (s Stream[T]) Wait(duration time.Duration) Stream[T]

The Wait function pauses the current stream for the duration passed. The first and only parameter expects a value from the built-in time.Duration package.

type Streamable

type Streamable interface {
	string | byte | float32 | float64 | int | int16 | int32 | int64 | uint16 | uint32 | uint64
}

The Streamable interface defines every type you can use the streams with.

type StructStream added in v1.2.0

type StructStream[T interface{}] struct {
	Array []T
}

func FromStructs added in v1.2.0

func FromStructs[T interface{}](array []T) StructStream[T]

The FromStruct function creates a new stream from the given struct array. If the given array is not made of struct, it throws an error.

func (StructStream[T]) All added in v1.2.0

func (s StructStream[T]) All(expression func(T) bool) bool

The All function determines whether all elements of the stream satisfy the passed condition.

func (StructStream[T]) Append added in v1.2.0

func (s StructStream[T]) Append(item T) StructStream[T]

The Append function adds an element to the stream.

func (StructStream[T]) AppendAt added in v1.2.0

func (s StructStream[T]) AppendAt(index int, item T) StructStream[T]

The AppendAt function inserts the specified element at the specified position in the stream.

func (StructStream[T]) AppendIf added in v1.2.0

func (s StructStream[T]) AppendIf(item T, c bool) StructStream[T]

The AppendIf function adds an element to the stream if the second parameter is true.

func (StructStream[T]) ArrEquals added in v1.2.0

func (s StructStream[T]) ArrEquals(arr []T) bool

The ArrEquals function compares the stream and the passed array and returns true if they're equals.

func (StructStream[T]) Average added in v1.2.0

func (s StructStream[T]) Average(fieldName string) float64

The Average function calculates the average of the stream. This function doesn't work with strings. The first parameter is the name of the field you want to calculate by.

func (StructStream[T]) Bind added in v1.3.1

func (s StructStream[T]) Bind(v *[]T)

The Bind function binds the stream into the passed variable.

func (StructStream[T]) Clear added in v1.2.0

func (s StructStream[T]) Clear() StructStream[T]

The Clear function clears every element from the stream.

func (StructStream[T]) Collect added in v1.2.0

func (s StructStream[T]) Collect() []T

The Collect function returns the modified array from the streams.

func (StructStream[T]) Contains added in v1.2.0

func (s StructStream[T]) Contains(item T) bool

The Contains function checks whether the stream contains the passed item.

func (StructStream[T]) Count added in v1.2.0

func (s StructStream[T]) Count() int

The Count function returns the count of elements in the stream.

func (StructStream[T]) ElementAt added in v1.2.0

func (s StructStream[T]) ElementAt(index int) T

The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it throws a panic.

func (StructStream[T]) ElementAtOrElse added in v1.2.0

func (s StructStream[T]) ElementAtOrElse(index int, elseValue T) T

The ElementAt function is used to get an element from the stream at a particular index. If the element is not present, it returns the elseValue, which is the second parameter.

func (StructStream[T]) Equals added in v1.2.0

func (s StructStream[T]) Equals(b StructStream[T]) bool

The Equals function compares two streams and returns true if they're equals.

func (StructStream[T]) Filter added in v1.2.0

func (s StructStream[T]) Filter(expression func(item T) bool) StructStream[T]

The Filter function leaves only those elements in the array that make the specified condition true.

func (StructStream[T]) Find added in v1.2.0

func (s StructStream[T]) Find(expression func(item T) bool) T

The Find function searches for an element that matches the conditions passed and returns the first occurrence within the entire stream.

func (StructStream[T]) FindIndex added in v1.2.0

func (s StructStream[T]) FindIndex(expression func(item T) bool) int

The FindIndex function searches for an element that matches the conditions passed and returns the index of the first occurrence within the entire stream.

func (StructStream[T]) FindLast added in v1.2.0

func (s StructStream[T]) FindLast(expression func(item T) bool) T

The FindLast function searches for an element that matches the conditions passed and returns the last occurrence within the entire stream.

func (StructStream[T]) FindLastIndex added in v1.2.0

func (s StructStream[T]) FindLastIndex(expression func(item T) bool) int

The FindLastIndex function searches for an element that matches the conditions passed and returns the index of the last occurrence within the entire stream.

func (StructStream[T]) First added in v1.2.1

func (s StructStream[T]) First() T

The First method returns the first element in the stream.

func (StructStream[T]) ForEach added in v1.2.0

func (s StructStream[T]) ForEach(expression func(item T))

The ForEach method runs the specified method with every element in the Stream.

func (StructStream[T]) IndexOf added in v1.2.0

func (s StructStream[T]) IndexOf(item T) int

The IndexOf function returns the position of the first occurrence of the passed value in a stream.

func (StructStream[T]) IsEmpty added in v1.2.0

func (s StructStream[T]) IsEmpty() bool

The IsEmpty function checks whether the stream is empty.

func (StructStream[T]) IsNotEmpty added in v1.2.1

func (s StructStream[T]) IsNotEmpty() bool

The IsNotEmpty function checks whether the stream is not empty.

func (StructStream[T]) Last added in v1.2.1

func (s StructStream[T]) Last() T

The Last method returns the last element in the stream.

func (StructStream[T]) LastIndexOf added in v1.2.0

func (s StructStream[T]) LastIndexOf(item T) int

The LastIndexOf function returns the position of the last occurrence of the passed value in a stream.

func (StructStream[T]) Limit added in v1.2.0

func (s StructStream[T]) Limit(amount int) StructStream[T]

The Limit function constrains the number of elements returned by the stream.

func (StructStream[T]) Map added in v1.2.0

func (s StructStream[T]) Map(expression func(item T) T) StructStream[T]

The Map function creates a new stream populated with the results of calling the provided function on every element.

func (StructStream[T]) Max added in v1.2.0

func (s StructStream[T]) Max(fieldName string) T

The Max function returns the largest element from the stream. The first parameter is the name of the field you want to calculate by.

func (StructStream[T]) MaxIndex added in v1.2.0

func (s StructStream[T]) MaxIndex(fieldName string) int

The MaxIndex function returns the index of the largest element from the stream. The first parameter is the name of the field you want to calculate by.

func (StructStream[T]) Min added in v1.2.0

func (s StructStream[T]) Min(fieldName string) T

The Min function returns the smallest element from the stream. The first parameter is the name of the field you want to calculate by.

func (StructStream[T]) MinIndex added in v1.2.0

func (s StructStream[T]) MinIndex(fieldName string) int

The MinIndex function returns the index of the smallest element from the stream. The first parameter is the name of the field you want to calculate by.

func (StructStream[T]) OrderBy added in v1.2.0

func (s StructStream[T]) OrderBy(fieldName string) StructStream[T]

The OrderBy function sorts the stream in ascending order. The first parameter is the name of the field you want to sort by.

func (StructStream[T]) OrderByDescending added in v1.2.0

func (s StructStream[T]) OrderByDescending(fieldName string) StructStream[T]

The OrderByDescending function sorts the stream in descending order The first parameter is the name of the field you want to sort by.

func (StructStream[T]) Push added in v1.2.3

func (s StructStream[T]) Push(arr []T) StructStream[T]

The Push function adds the passed array to the end of the stream.

func (StructStream[T]) PushValues added in v1.2.3

func (s StructStream[T]) PushValues(values ...T) StructStream[T]

The PushValues function adds the passed values to the end of the stream.

func (StructStream[T]) Remove added in v1.2.0

func (s StructStream[T]) Remove(item T) StructStream[T]

The Remove function removes the passed element from a stream.

func (StructStream[T]) RemoveAt added in v1.2.0

func (s StructStream[T]) RemoveAt(index int) StructStream[T]

The RemoveAt function removes the item if its index matches the index passed in.

func (StructStream[T]) RemoveIf added in v1.2.0

func (s StructStream[T]) RemoveIf(item T, c bool) StructStream[T]

The RemoveIf function removes the passed element from a stream if the second parameter is true.

func (StructStream[T]) RemoveWhere added in v1.2.0

func (s StructStream[T]) RemoveWhere(expression func(item T) bool) StructStream[T]

The RemoveWhere function removes all the entries that satisfy the provided condition.

func (StructStream[T]) Replace added in v1.2.2

func (s StructStream[T]) Replace(from T, to T) StructStream[T]

The Replace function replaces every occurrence of 'from' to 'to'. The first parameter is 'from', and the second is 'to'.

func (StructStream[T]) ReplaceWhere added in v1.2.2

func (s StructStream[T]) ReplaceWhere(function func(item T) bool, to T) StructStream[T]

The ReplaceWhere function replaces every element that satisfies the condition.

func (StructStream[T]) Reverse added in v1.2.0

func (s StructStream[T]) Reverse() StructStream[T]

The Reverse function reverses the stream.

func (StructStream[T]) Shuffle added in v1.2.1

func (s StructStream[T]) Shuffle() StructStream[T]

The Shuffle function shuffles the stream.

func (StructStream[T]) Skip added in v1.3.1

func (s StructStream[T]) Skip(amount int) StructStream[T]

The Skip function discards the first n elements of a stream, where n is the passed parameter.

func (StructStream[T]) Slice added in v1.2.2

func (s StructStream[T]) Slice(start int, end int) StructStream[T]

The Slice function returns a copy of a portion of a stream into a new stream selected from start to end (end not included) where start and end represent the index of items in the stream.

func (StructStream[T]) Some added in v1.2.0

func (s StructStream[T]) Some(expression func(item T) bool) bool

The Some function determines whether any of the elements of the stream satisfy the passed condition.

func (StructStream[T]) Sum added in v1.2.0

func (s StructStream[T]) Sum(fieldName string) float64

The Sum function adds up all values in a stream. The first parameter is the name of the field you want to calculate by.

func (StructStream[T]) Wait added in v1.2.0

func (s StructStream[T]) Wait(duration time.Duration) StructStream[T]

The Wait function pauses the current stream for the duration passed. The first and only parameter expects a value from the built-in time.Duration package.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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