Note: This is a work in progress. I will be adding more tools as I find them.
Save your life!
go get -u github.com/carter-ya/go-tools
items:= []int64{1, 2, 3, 4, 5}
s := stream.From(func(source chan<- any) {
for _, item := range items {
source <- item
}
})
s := stream.Just([]int64{1, 2, 3, 4, 5})
s := stream.Range[int64](0, 100)
s1 := stream.Just([]int64{1, 2, 3, 4, 5})
s2 := stream.Range[int64](0, 100)
s := Concat(s1, []stream.Stream{s2})
All the methods above can be used to create a parallel stream,
just add stream.WithParallelism()
to the end of the method name.
For example:
s := stream.Range[int64](0, 100, stream.WithParallelism(4))
s1 := stream.Just([]int64{1, 2, 3, 4, 5}, stream.WithParallelism(4))
All the methods of stream.Stream
can be used to convert a parallel stream to a synchronous stream,
just add stream.WithSync()
to the end of the method name.
For example:
s := stream.Range[int64](0, 100, stream.WithParallelism(4)).Filter(func(item any) bool {
return item.(int64) > 50
}, stream.WithSync())
More details can be found in the stream.go file.
- Map
- FlatMap
- Filter
- Concat
- Sort
- Distinct
- Skip
- Limit
- TakeWhile
- DropWhile
- Peek
- AnyMatch
- AllMatch
- NoneMatch
- FindFirst
- Count
- Reduce
- ForEach
- ToIfaceSlice
- Collect
- Close
More details can be found in the collectors.go file.
- Identify
- MapSupplier
- MapSupplierWithSize
- SliceSupplier
- JoiningSupplier
- GroupBySupplier
- collection.Shuffle (shuffle a slice)
- collection.Reverse (reverse a slice)
- _map.Keys (get all keys of a map)
- _map.Values (get all values of a map)
- _map.ForEach (iterate a map)
- _map.ForEachIndexed (iterate a map with index)
- _map.Copy (copy a map)
- _map.CopyTo (copy a map to another map)
- _map.GetOrDefault (get value of a map by key, if the key does not exist, return the default value)
- _map.ComputeIfAbsent (get value of a map by key, if the key does not exist, compute the value and put it into the map)
- _map.KeysAsStream (get all keys of a map as a stream)
- _map.ValuesAsStream (get all values of a map as a stream)
- _map.MapAsStream (get all key-value pairs of a map as a stream)
More details can be found in the map.go file.
- Put
- PutIfAbsent
- PutAll
- ComputeIfAbsent
- ComputeIfPresent
- Get
- GetOrDefault
- ContainsKey
- Keys
- Values
- ForEach
- ForEachIndexed
- Remove
- RemoveIf
- Clear
- IsEmpty
- Size
- AsBuiltinMap
It is based on the builtin map
, so it is not thread-safe.
type HashMap[K comparable, V any] map[K]V
How to create a HashMap
NewHashMap()
NewHashMapWithSize(size int)
NewHashMapWithMap(m Map[K]V)
NewHashMapFromBuiltinMap(m map[K]V)
It is based on the HashMap
, so it is not thread-safe.
How to create a LinkedHashMap
NewLinkedHashMap()
NewLinkedHashMapWithSize(size int)
NewLinkedHashMapWithMap(m Map[K]V)
More details can be found in the collection.go file.
- Add
- AddAll
- Remove
- RemoveAll
- RemoveIff
- RetainAll
- Clear
- Contains
- ContainsAll
- IsEmpty
- Size
- ForEach
- ForEachIndexed
- AsSlice
- Stream
More details can be found in the list.go file.
- Add
- AddAll
- Remove
- RemoveAll
- RemoveIff
- RetainAll
- Clear
- Contains
- ContainsAll
- IsEmpty
- Size
- ForEach
- ForEachIndexed
- AsSlice
- Stream
It is based on the builtin slice
, so it is not thread-safe.
How to create a ArrayList
NewArrayList()
NewArrayListWithSize(size int)
NewArrayListWithSlice(s []T)
NewArrayListWithCollection(c Collection[T])
NewArrayListWithStream(s Stream[T])
More details can be found in the set.go file.
- Add
- AddAll
- Remove
- RemoveAll
- RemoveIf
- RetainAll
- Clear
- Contains
- ContainsAll
- IsEmpty
- Size
- ForEach
- ForEachIndexed
- AsSlice
- Stream
It is based on the builtin map
, so it is not thread-safe.
type HashSet[E comparable] map[T]struct{}
How to create a HashSet
NewHashSet()
NewHashSetWithSize(size int)
NewHashSetWithSlice(s []E)
NewHashSetFromCollection(s Set[E])
NewHashSetFromStream(s stream.Stream)
It is based on the LinkedHashMap
, so it is not thread-safe.
How to create a LinkedHashSet
NewLinkedHashSet()
NewLinkedHashSetWithSize(size int)
NewLinkedHashSetWithSlice(s []E)
NewLinkedHashSetFromCollection(s Set[E])
NewLinkedHashSetFromStream(s stream.Stream)