Switch remote deploy to vendored source builds
Move remote deployment to a vendored source bundle built on the target host via Docker so redeploys no longer require local cross-compilation or host Go installation. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
13
vendor/github.com/leaanthony/slicer/.gitignore
generated
vendored
Normal file
13
vendor/github.com/leaanthony/slicer/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
coverage.txt
|
||||
39
vendor/github.com/leaanthony/slicer/CHANGELOG.md
generated
vendored
Normal file
39
vendor/github.com/leaanthony/slicer/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<a name="unreleased"></a>
|
||||
## [Unreleased]
|
||||
|
||||
|
||||
<a name="v1.3.1"></a>
|
||||
## [v1.3.1] - 2019-03-03
|
||||
### Fix
|
||||
- Fix Float tests
|
||||
|
||||
|
||||
<a name="v1.3.0"></a>
|
||||
## [v1.3.0] - 2019-03-03
|
||||
### Feat
|
||||
- Add optional slice as part of construction
|
||||
|
||||
|
||||
<a name="v1.2.0"></a>
|
||||
## [v1.2.0] - 2019-02-26
|
||||
### Chore
|
||||
- add changelog
|
||||
|
||||
### Feat
|
||||
- Add Slicer.Each()
|
||||
|
||||
|
||||
<a name="v1.1.0"></a>
|
||||
## [v1.1.0] - 2019-02-26
|
||||
### Feat
|
||||
- Added Filter
|
||||
|
||||
|
||||
<a name="v1.0.0"></a>
|
||||
## v1.0.0 - 2019-01-13
|
||||
|
||||
[Unreleased]: https://github.com/leaanthony/slicer/compare/v1.3.1...HEAD
|
||||
[v1.3.1]: https://github.com/leaanthony/slicer/compare/v1.3.0...v1.3.1
|
||||
[v1.3.0]: https://github.com/leaanthony/slicer/compare/v1.2.0...v1.3.0
|
||||
[v1.2.0]: https://github.com/leaanthony/slicer/compare/v1.1.0...v1.2.0
|
||||
[v1.1.0]: https://github.com/leaanthony/slicer/compare/v1.0.0...v1.1.0
|
||||
21
vendor/github.com/leaanthony/slicer/LICENSE
generated
vendored
Normal file
21
vendor/github.com/leaanthony/slicer/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Lea Anthony
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
216
vendor/github.com/leaanthony/slicer/README.md
generated
vendored
Normal file
216
vendor/github.com/leaanthony/slicer/README.md
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
|
||||
<div style="text-align:center; width:400px">
|
||||
<img src="logo.png"/>
|
||||
Utility class for handling slices.
|
||||
</div>
|
||||
|
||||
|
||||
[](https://goreportcard.com/report/github.com/leaanthony/slicer) [](http://godoc.org/github.com/leaanthony/slicer) [](https://www.codefactor.io/repository/github/leaanthony/slicer) [](https://codecov.io/gh/leaanthony/slicer) [](https://github.com/avelino/awesome-go)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
`go get -u github.com/leaanthony/slicer`
|
||||
|
||||
## Quick Start
|
||||
|
||||
```
|
||||
import "github.com/leaanthony/slicer"
|
||||
|
||||
func test() {
|
||||
s := slicer.String()
|
||||
s.Add("one")
|
||||
s.Add("two")
|
||||
s.AddSlice([]string{"three","four"})
|
||||
fmt.Printf("My slice = %+v\n", s.AsSlice())
|
||||
|
||||
t := slicer.String()
|
||||
t.Add("zero")
|
||||
t.AddSlicer(s)
|
||||
fmt.Printf("My slice = %+v\n", t.AsSlice())
|
||||
}
|
||||
```
|
||||
|
||||
## Available slicers
|
||||
|
||||
- Int
|
||||
- Int8
|
||||
- Int16
|
||||
- Int32
|
||||
- Int64
|
||||
- UInt
|
||||
- UInt8
|
||||
- UInt16
|
||||
- UInt32
|
||||
- UInt64
|
||||
- Float32
|
||||
- Float64
|
||||
- String
|
||||
- Bool
|
||||
- Interface
|
||||
|
||||
## API
|
||||
|
||||
### Construction
|
||||
|
||||
Create new Slicers by calling one of the following functions:
|
||||
- Int()
|
||||
- Int8()
|
||||
- Int16()
|
||||
- Int32()
|
||||
- Int64()
|
||||
- Float32()
|
||||
- Float64()
|
||||
- String()
|
||||
- Bool()
|
||||
- Interface()
|
||||
|
||||
```
|
||||
s := slicer.String()
|
||||
```
|
||||
|
||||
If you wish to convert an existing slice to a Slicer, you may pass it in during creation:
|
||||
|
||||
```
|
||||
values := []string{"one", "two", "three"}
|
||||
s := slicer.String(values)
|
||||
```
|
||||
|
||||
### Add
|
||||
|
||||
Adds a value to the slice.
|
||||
|
||||
```
|
||||
values := []string{"one", "two", "three"}
|
||||
s := slicer.String(values)
|
||||
s.Add("four")
|
||||
```
|
||||
|
||||
### AddUnique
|
||||
|
||||
Adds a value to the slice if it doesn't already contain it.
|
||||
|
||||
```
|
||||
values := []string{"one", "two", "three", "one", "two", "three"}
|
||||
s := slicer.String(values)
|
||||
result := s.Join(",")
|
||||
// result is "one,two,three"
|
||||
```
|
||||
### AddSlice
|
||||
|
||||
Adds an existing slice of values to a slicer
|
||||
|
||||
```
|
||||
s := slicer.String([]string{"one"})
|
||||
s.AddSlice([]string{"two"})
|
||||
```
|
||||
|
||||
### AsSlice
|
||||
|
||||
Returns a regular slice from the slicer.
|
||||
|
||||
```
|
||||
s := slicer.String([]string{"one"})
|
||||
for _, value := range s.AsSlice() {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### AddSlicer
|
||||
|
||||
Adds an existing slicer of values to another slicer
|
||||
|
||||
```
|
||||
a := slicer.String([]string{"one"})
|
||||
b := slicer.String([]string{"two"})
|
||||
a.AddSlicer(b)
|
||||
```
|
||||
|
||||
### Filter
|
||||
|
||||
Filter the values of a slicer based on the result of calling the given function with each value of the slice. If it returns true, the value is added to the result.
|
||||
|
||||
```
|
||||
a := slicer.Int([]int{1,5,7,9,6,3,1,9,1})
|
||||
result := a.Filter(func(v int) bool {
|
||||
return v > 5
|
||||
})
|
||||
// result is []int{7,9,9}
|
||||
|
||||
```
|
||||
|
||||
### Each
|
||||
|
||||
Each iterates over all the values of a slicer, passing them in as paramter to a function
|
||||
|
||||
```
|
||||
a := slicer.Int([]int{1,5,7,9,6,3,1,9,1})
|
||||
result := 0
|
||||
a.Each(func(v int) {
|
||||
result += v
|
||||
})
|
||||
// result is 42
|
||||
```
|
||||
|
||||
### Contains
|
||||
|
||||
Contains returns true if the slicer contains the given value
|
||||
|
||||
```
|
||||
a := slicer.Int([]int{1,5,7,9,6,3,1,9,1})
|
||||
result := a.Contains(9)
|
||||
// result is True
|
||||
```
|
||||
|
||||
### Join
|
||||
|
||||
Returns a string with the slicer elements separated by the given separator
|
||||
|
||||
```
|
||||
a := slicer.String([]string{"one", "two", "three"})
|
||||
result := a.Join(",")
|
||||
// result is "one,two,three"
|
||||
```
|
||||
### Length
|
||||
|
||||
Returns the length of the slice
|
||||
|
||||
```
|
||||
a := slicer.String([]string{"one", "two", "three"})
|
||||
result := a.Length()
|
||||
// result is 3
|
||||
```
|
||||
|
||||
### Clear
|
||||
|
||||
Clears all elements from the current slice
|
||||
|
||||
```
|
||||
a := slicer.String([]string{"one", "two", "three"})
|
||||
a.Clear()
|
||||
// a.Length() == 0
|
||||
```
|
||||
|
||||
### Sort
|
||||
|
||||
Sorts the elements of a slice
|
||||
Not supported by: InterfaceSlicer, BoolSlicer
|
||||
|
||||
```
|
||||
a := slicer.Int([]int{5,3,4,1,2})
|
||||
a.Sort()
|
||||
// a is []int{1,2,3,4,5}
|
||||
```
|
||||
|
||||
### Deduplicate
|
||||
|
||||
Deduplicate removes all duplicates within a slice.
|
||||
|
||||
```
|
||||
a := slicer.Int([]int{5,3,5,1,3})
|
||||
a.Deduplicate()
|
||||
// a is []int{5,3,1}
|
||||
```
|
||||
127
vendor/github.com/leaanthony/slicer/bool.go
generated
vendored
Normal file
127
vendor/github.com/leaanthony/slicer/bool.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// BoolSlicer handles slices of bool
|
||||
type BoolSlicer struct {
|
||||
slice []bool
|
||||
}
|
||||
|
||||
// Bool creates a new BoolSlicer
|
||||
func Bool(slice ...[]bool) *BoolSlicer {
|
||||
if len(slice) > 0 {
|
||||
return &BoolSlicer{slice: slice[0]}
|
||||
}
|
||||
return &BoolSlicer{}
|
||||
}
|
||||
|
||||
// Add a bool value to the slicer
|
||||
func (s *BoolSlicer) Add(value bool, additional ...bool) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a bool value to the slicer if it does not already exist
|
||||
func (s *BoolSlicer) AddUnique(value bool, additional ...bool) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a bool slice to the slicer
|
||||
func (s *BoolSlicer) AddSlice(value []bool) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *BoolSlicer) AsSlice() []bool {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a BoolSlicer to the slicer
|
||||
func (s *BoolSlicer) AddSlicer(value *BoolSlicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *BoolSlicer) Filter(fn func(bool) bool) *BoolSlicer {
|
||||
result := &BoolSlicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *BoolSlicer) Each(fn func(bool)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *BoolSlicer) Contains(matcher bool) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *BoolSlicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *BoolSlicer) Clear() {
|
||||
s.slice = []bool{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *BoolSlicer) Deduplicate() {
|
||||
|
||||
result := &BoolSlicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *BoolSlicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/float32.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/float32.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Float32Slicer handles slices of float32
|
||||
type Float32Slicer struct {
|
||||
slice []float32
|
||||
}
|
||||
|
||||
// Float32 creates a new Float32Slicer
|
||||
func Float32(slice ...[]float32) *Float32Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Float32Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Float32Slicer{}
|
||||
}
|
||||
|
||||
// Add a float32 value to the slicer
|
||||
func (s *Float32Slicer) Add(value float32, additional ...float32) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a float32 value to the slicer if it does not already exist
|
||||
func (s *Float32Slicer) AddUnique(value float32, additional ...float32) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a float32 slice to the slicer
|
||||
func (s *Float32Slicer) AddSlice(value []float32) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Float32Slicer) AsSlice() []float32 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Float32Slicer to the slicer
|
||||
func (s *Float32Slicer) AddSlicer(value *Float32Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Float32Slicer) Filter(fn func(float32) bool) *Float32Slicer {
|
||||
result := &Float32Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Float32Slicer) Each(fn func(float32)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Float32Slicer) Contains(matcher float32) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Float32Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Float32Slicer) Clear() {
|
||||
s.slice = []float32{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Float32Slicer) Deduplicate() {
|
||||
|
||||
result := &Float32Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Float32Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Float32Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/float64.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/float64.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Float64Slicer handles slices of float64
|
||||
type Float64Slicer struct {
|
||||
slice []float64
|
||||
}
|
||||
|
||||
// Float64 creates a new Float64Slicer
|
||||
func Float64(slice ...[]float64) *Float64Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Float64Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Float64Slicer{}
|
||||
}
|
||||
|
||||
// Add a float64 value to the slicer
|
||||
func (s *Float64Slicer) Add(value float64, additional ...float64) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a float64 value to the slicer if it does not already exist
|
||||
func (s *Float64Slicer) AddUnique(value float64, additional ...float64) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a float64 slice to the slicer
|
||||
func (s *Float64Slicer) AddSlice(value []float64) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Float64Slicer) AsSlice() []float64 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Float64Slicer to the slicer
|
||||
func (s *Float64Slicer) AddSlicer(value *Float64Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Float64Slicer) Filter(fn func(float64) bool) *Float64Slicer {
|
||||
result := &Float64Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Float64Slicer) Each(fn func(float64)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Float64Slicer) Contains(matcher float64) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Float64Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Float64Slicer) Clear() {
|
||||
s.slice = []float64{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Float64Slicer) Deduplicate() {
|
||||
|
||||
result := &Float64Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Float64Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Float64Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/int.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/int.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// IntSlicer handles slices of int
|
||||
type IntSlicer struct {
|
||||
slice []int
|
||||
}
|
||||
|
||||
// Int creates a new IntSlicer
|
||||
func Int(slice ...[]int) *IntSlicer {
|
||||
if len(slice) > 0 {
|
||||
return &IntSlicer{slice: slice[0]}
|
||||
}
|
||||
return &IntSlicer{}
|
||||
}
|
||||
|
||||
// Add a int value to the slicer
|
||||
func (s *IntSlicer) Add(value int, additional ...int) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a int value to the slicer if it does not already exist
|
||||
func (s *IntSlicer) AddUnique(value int, additional ...int) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a int slice to the slicer
|
||||
func (s *IntSlicer) AddSlice(value []int) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *IntSlicer) AsSlice() []int {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a IntSlicer to the slicer
|
||||
func (s *IntSlicer) AddSlicer(value *IntSlicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *IntSlicer) Filter(fn func(int) bool) *IntSlicer {
|
||||
result := &IntSlicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *IntSlicer) Each(fn func(int)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *IntSlicer) Contains(matcher int) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *IntSlicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *IntSlicer) Clear() {
|
||||
s.slice = []int{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *IntSlicer) Deduplicate() {
|
||||
|
||||
result := &IntSlicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *IntSlicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *IntSlicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/int16.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/int16.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Int16Slicer handles slices of int16
|
||||
type Int16Slicer struct {
|
||||
slice []int16
|
||||
}
|
||||
|
||||
// Int16 creates a new Int16Slicer
|
||||
func Int16(slice ...[]int16) *Int16Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Int16Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Int16Slicer{}
|
||||
}
|
||||
|
||||
// Add a int16 value to the slicer
|
||||
func (s *Int16Slicer) Add(value int16, additional ...int16) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a int16 value to the slicer if it does not already exist
|
||||
func (s *Int16Slicer) AddUnique(value int16, additional ...int16) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a int16 slice to the slicer
|
||||
func (s *Int16Slicer) AddSlice(value []int16) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Int16Slicer) AsSlice() []int16 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Int16Slicer to the slicer
|
||||
func (s *Int16Slicer) AddSlicer(value *Int16Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Int16Slicer) Filter(fn func(int16) bool) *Int16Slicer {
|
||||
result := &Int16Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Int16Slicer) Each(fn func(int16)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Int16Slicer) Contains(matcher int16) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Int16Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Int16Slicer) Clear() {
|
||||
s.slice = []int16{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Int16Slicer) Deduplicate() {
|
||||
|
||||
result := &Int16Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Int16Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Int16Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/int32.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/int32.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Int32Slicer handles slices of int32
|
||||
type Int32Slicer struct {
|
||||
slice []int32
|
||||
}
|
||||
|
||||
// Int32 creates a new Int32Slicer
|
||||
func Int32(slice ...[]int32) *Int32Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Int32Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Int32Slicer{}
|
||||
}
|
||||
|
||||
// Add a int32 value to the slicer
|
||||
func (s *Int32Slicer) Add(value int32, additional ...int32) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a int32 value to the slicer if it does not already exist
|
||||
func (s *Int32Slicer) AddUnique(value int32, additional ...int32) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a int32 slice to the slicer
|
||||
func (s *Int32Slicer) AddSlice(value []int32) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Int32Slicer) AsSlice() []int32 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Int32Slicer to the slicer
|
||||
func (s *Int32Slicer) AddSlicer(value *Int32Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Int32Slicer) Filter(fn func(int32) bool) *Int32Slicer {
|
||||
result := &Int32Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Int32Slicer) Each(fn func(int32)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Int32Slicer) Contains(matcher int32) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Int32Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Int32Slicer) Clear() {
|
||||
s.slice = []int32{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Int32Slicer) Deduplicate() {
|
||||
|
||||
result := &Int32Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Int32Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Int32Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/int64.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/int64.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Int64Slicer handles slices of int64
|
||||
type Int64Slicer struct {
|
||||
slice []int64
|
||||
}
|
||||
|
||||
// Int64 creates a new Int64Slicer
|
||||
func Int64(slice ...[]int64) *Int64Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Int64Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Int64Slicer{}
|
||||
}
|
||||
|
||||
// Add a int64 value to the slicer
|
||||
func (s *Int64Slicer) Add(value int64, additional ...int64) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a int64 value to the slicer if it does not already exist
|
||||
func (s *Int64Slicer) AddUnique(value int64, additional ...int64) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a int64 slice to the slicer
|
||||
func (s *Int64Slicer) AddSlice(value []int64) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Int64Slicer) AsSlice() []int64 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Int64Slicer to the slicer
|
||||
func (s *Int64Slicer) AddSlicer(value *Int64Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Int64Slicer) Filter(fn func(int64) bool) *Int64Slicer {
|
||||
result := &Int64Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Int64Slicer) Each(fn func(int64)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Int64Slicer) Contains(matcher int64) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Int64Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Int64Slicer) Clear() {
|
||||
s.slice = []int64{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Int64Slicer) Deduplicate() {
|
||||
|
||||
result := &Int64Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Int64Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Int64Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/int8.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/int8.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Int8Slicer handles slices of int8
|
||||
type Int8Slicer struct {
|
||||
slice []int8
|
||||
}
|
||||
|
||||
// Int8 creates a new Int8Slicer
|
||||
func Int8(slice ...[]int8) *Int8Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Int8Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Int8Slicer{}
|
||||
}
|
||||
|
||||
// Add a int8 value to the slicer
|
||||
func (s *Int8Slicer) Add(value int8, additional ...int8) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a int8 value to the slicer if it does not already exist
|
||||
func (s *Int8Slicer) AddUnique(value int8, additional ...int8) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a int8 slice to the slicer
|
||||
func (s *Int8Slicer) AddSlice(value []int8) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Int8Slicer) AsSlice() []int8 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Int8Slicer to the slicer
|
||||
func (s *Int8Slicer) AddSlicer(value *Int8Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Int8Slicer) Filter(fn func(int8) bool) *Int8Slicer {
|
||||
result := &Int8Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Int8Slicer) Each(fn func(int8)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Int8Slicer) Contains(matcher int8) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Int8Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Int8Slicer) Clear() {
|
||||
s.slice = []int8{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Int8Slicer) Deduplicate() {
|
||||
|
||||
result := &Int8Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Int8Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Int8Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
127
vendor/github.com/leaanthony/slicer/interface.go
generated
vendored
Normal file
127
vendor/github.com/leaanthony/slicer/interface.go
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// InterfaceSlicer handles slices of interface{}
|
||||
type InterfaceSlicer struct {
|
||||
slice []interface{}
|
||||
}
|
||||
|
||||
// Interface creates a new InterfaceSlicer
|
||||
func Interface(slice ...[]interface{}) *InterfaceSlicer {
|
||||
if len(slice) > 0 {
|
||||
return &InterfaceSlicer{slice: slice[0]}
|
||||
}
|
||||
return &InterfaceSlicer{}
|
||||
}
|
||||
|
||||
// Add a interface{} value to the slicer
|
||||
func (s *InterfaceSlicer) Add(value interface{}, additional ...interface{}) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a interface{} value to the slicer if it does not already exist
|
||||
func (s *InterfaceSlicer) AddUnique(value interface{}, additional ...interface{}) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a interface{} slice to the slicer
|
||||
func (s *InterfaceSlicer) AddSlice(value []interface{}) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *InterfaceSlicer) AsSlice() []interface{} {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a InterfaceSlicer to the slicer
|
||||
func (s *InterfaceSlicer) AddSlicer(value *InterfaceSlicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *InterfaceSlicer) Filter(fn func(interface{}) bool) *InterfaceSlicer {
|
||||
result := &InterfaceSlicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *InterfaceSlicer) Each(fn func(interface{})) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *InterfaceSlicer) Contains(matcher interface{}) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *InterfaceSlicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *InterfaceSlicer) Clear() {
|
||||
s.slice = []interface{}{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *InterfaceSlicer) Deduplicate() {
|
||||
|
||||
result := &InterfaceSlicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *InterfaceSlicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
BIN
vendor/github.com/leaanthony/slicer/logo.png
generated
vendored
Normal file
BIN
vendor/github.com/leaanthony/slicer/logo.png
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
118
vendor/github.com/leaanthony/slicer/string.go
generated
vendored
Normal file
118
vendor/github.com/leaanthony/slicer/string.go
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "strings"
|
||||
|
||||
// StringSlicer handles slices of string
|
||||
type StringSlicer struct {
|
||||
slice []string
|
||||
}
|
||||
|
||||
// String creates a new StringSlicer
|
||||
func String(slice ...[]string) *StringSlicer {
|
||||
if len(slice) > 0 {
|
||||
return &StringSlicer{slice: slice[0]}
|
||||
}
|
||||
return &StringSlicer{}
|
||||
}
|
||||
|
||||
// Add a string value to the slicer
|
||||
func (s *StringSlicer) Add(value string, additional ...string) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a string value to the slicer if it does not already exist
|
||||
func (s *StringSlicer) AddUnique(value string, additional ...string) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a string slice to the slicer
|
||||
func (s *StringSlicer) AddSlice(value []string) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *StringSlicer) AsSlice() []string {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a StringSlicer to the slicer
|
||||
func (s *StringSlicer) AddSlicer(value *StringSlicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *StringSlicer) Filter(fn func(string) bool) *StringSlicer {
|
||||
result := &StringSlicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *StringSlicer) Each(fn func(string)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *StringSlicer) Contains(matcher string) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *StringSlicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *StringSlicer) Clear() {
|
||||
s.slice = []string{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *StringSlicer) Deduplicate() {
|
||||
|
||||
result := &StringSlicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *StringSlicer) Join(separator string) string {
|
||||
return strings.Join(s.slice, separator)
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *StringSlicer) Sort() {
|
||||
sort.Strings(s.slice)
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/uint.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/uint.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// UintSlicer handles slices of uint
|
||||
type UintSlicer struct {
|
||||
slice []uint
|
||||
}
|
||||
|
||||
// Uint creates a new UintSlicer
|
||||
func Uint(slice ...[]uint) *UintSlicer {
|
||||
if len(slice) > 0 {
|
||||
return &UintSlicer{slice: slice[0]}
|
||||
}
|
||||
return &UintSlicer{}
|
||||
}
|
||||
|
||||
// Add a uint value to the slicer
|
||||
func (s *UintSlicer) Add(value uint, additional ...uint) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a uint value to the slicer if it does not already exist
|
||||
func (s *UintSlicer) AddUnique(value uint, additional ...uint) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a uint slice to the slicer
|
||||
func (s *UintSlicer) AddSlice(value []uint) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *UintSlicer) AsSlice() []uint {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a UintSlicer to the slicer
|
||||
func (s *UintSlicer) AddSlicer(value *UintSlicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *UintSlicer) Filter(fn func(uint) bool) *UintSlicer {
|
||||
result := &UintSlicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *UintSlicer) Each(fn func(uint)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *UintSlicer) Contains(matcher uint) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *UintSlicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *UintSlicer) Clear() {
|
||||
s.slice = []uint{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *UintSlicer) Deduplicate() {
|
||||
|
||||
result := &UintSlicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *UintSlicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *UintSlicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/uint16.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/uint16.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Uint16Slicer handles slices of uint16
|
||||
type Uint16Slicer struct {
|
||||
slice []uint16
|
||||
}
|
||||
|
||||
// Uint16 creates a new Uint16Slicer
|
||||
func Uint16(slice ...[]uint16) *Uint16Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Uint16Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Uint16Slicer{}
|
||||
}
|
||||
|
||||
// Add a uint16 value to the slicer
|
||||
func (s *Uint16Slicer) Add(value uint16, additional ...uint16) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a uint16 value to the slicer if it does not already exist
|
||||
func (s *Uint16Slicer) AddUnique(value uint16, additional ...uint16) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a uint16 slice to the slicer
|
||||
func (s *Uint16Slicer) AddSlice(value []uint16) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Uint16Slicer) AsSlice() []uint16 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Uint16Slicer to the slicer
|
||||
func (s *Uint16Slicer) AddSlicer(value *Uint16Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Uint16Slicer) Filter(fn func(uint16) bool) *Uint16Slicer {
|
||||
result := &Uint16Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Uint16Slicer) Each(fn func(uint16)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Uint16Slicer) Contains(matcher uint16) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Uint16Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Uint16Slicer) Clear() {
|
||||
s.slice = []uint16{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Uint16Slicer) Deduplicate() {
|
||||
|
||||
result := &Uint16Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Uint16Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Uint16Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/uint32.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/uint32.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Uint32Slicer handles slices of uint32
|
||||
type Uint32Slicer struct {
|
||||
slice []uint32
|
||||
}
|
||||
|
||||
// Uint32 creates a new Uint32Slicer
|
||||
func Uint32(slice ...[]uint32) *Uint32Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Uint32Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Uint32Slicer{}
|
||||
}
|
||||
|
||||
// Add a uint32 value to the slicer
|
||||
func (s *Uint32Slicer) Add(value uint32, additional ...uint32) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a uint32 value to the slicer if it does not already exist
|
||||
func (s *Uint32Slicer) AddUnique(value uint32, additional ...uint32) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a uint32 slice to the slicer
|
||||
func (s *Uint32Slicer) AddSlice(value []uint32) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Uint32Slicer) AsSlice() []uint32 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Uint32Slicer to the slicer
|
||||
func (s *Uint32Slicer) AddSlicer(value *Uint32Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Uint32Slicer) Filter(fn func(uint32) bool) *Uint32Slicer {
|
||||
result := &Uint32Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Uint32Slicer) Each(fn func(uint32)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Uint32Slicer) Contains(matcher uint32) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Uint32Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Uint32Slicer) Clear() {
|
||||
s.slice = []uint32{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Uint32Slicer) Deduplicate() {
|
||||
|
||||
result := &Uint32Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Uint32Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Uint32Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/uint64.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/uint64.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Uint64Slicer handles slices of uint64
|
||||
type Uint64Slicer struct {
|
||||
slice []uint64
|
||||
}
|
||||
|
||||
// Uint64 creates a new Uint64Slicer
|
||||
func Uint64(slice ...[]uint64) *Uint64Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Uint64Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Uint64Slicer{}
|
||||
}
|
||||
|
||||
// Add a uint64 value to the slicer
|
||||
func (s *Uint64Slicer) Add(value uint64, additional ...uint64) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a uint64 value to the slicer if it does not already exist
|
||||
func (s *Uint64Slicer) AddUnique(value uint64, additional ...uint64) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a uint64 slice to the slicer
|
||||
func (s *Uint64Slicer) AddSlice(value []uint64) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Uint64Slicer) AsSlice() []uint64 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Uint64Slicer to the slicer
|
||||
func (s *Uint64Slicer) AddSlicer(value *Uint64Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Uint64Slicer) Filter(fn func(uint64) bool) *Uint64Slicer {
|
||||
result := &Uint64Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Uint64Slicer) Each(fn func(uint64)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Uint64Slicer) Contains(matcher uint64) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Uint64Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Uint64Slicer) Clear() {
|
||||
s.slice = []uint64{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Uint64Slicer) Deduplicate() {
|
||||
|
||||
result := &Uint64Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Uint64Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Uint64Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
133
vendor/github.com/leaanthony/slicer/uint8.go
generated
vendored
Normal file
133
vendor/github.com/leaanthony/slicer/uint8.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// Package slicer contains utility classes for handling slices
|
||||
package slicer
|
||||
|
||||
// Imports
|
||||
import "sort"
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
// Uint8Slicer handles slices of uint8
|
||||
type Uint8Slicer struct {
|
||||
slice []uint8
|
||||
}
|
||||
|
||||
// Uint8 creates a new Uint8Slicer
|
||||
func Uint8(slice ...[]uint8) *Uint8Slicer {
|
||||
if len(slice) > 0 {
|
||||
return &Uint8Slicer{slice: slice[0]}
|
||||
}
|
||||
return &Uint8Slicer{}
|
||||
}
|
||||
|
||||
// Add a uint8 value to the slicer
|
||||
func (s *Uint8Slicer) Add(value uint8, additional ...uint8) {
|
||||
s.slice = append(s.slice, value)
|
||||
s.slice = append(s.slice, additional...)
|
||||
}
|
||||
|
||||
// AddUnique adds a uint8 value to the slicer if it does not already exist
|
||||
func (s *Uint8Slicer) AddUnique(value uint8, additional ...uint8) {
|
||||
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
|
||||
// Add additional values
|
||||
for _, value := range additional {
|
||||
if !s.Contains(value) {
|
||||
s.slice = append(s.slice, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AddSlice adds a uint8 slice to the slicer
|
||||
func (s *Uint8Slicer) AddSlice(value []uint8) {
|
||||
s.slice = append(s.slice, value...)
|
||||
}
|
||||
|
||||
// AsSlice returns the slice
|
||||
func (s *Uint8Slicer) AsSlice() []uint8 {
|
||||
return s.slice
|
||||
}
|
||||
|
||||
// AddSlicer appends a Uint8Slicer to the slicer
|
||||
func (s *Uint8Slicer) AddSlicer(value *Uint8Slicer) {
|
||||
s.slice = append(s.slice, value.AsSlice()...)
|
||||
}
|
||||
|
||||
// Filter the slice based on the given function
|
||||
func (s *Uint8Slicer) Filter(fn func(uint8) bool) *Uint8Slicer {
|
||||
result := &Uint8Slicer{}
|
||||
for _, elem := range s.slice {
|
||||
if fn(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Each runs a function on every element of the slice
|
||||
func (s *Uint8Slicer) Each(fn func(uint8)) {
|
||||
for _, elem := range s.slice {
|
||||
fn(elem)
|
||||
}
|
||||
}
|
||||
|
||||
// Contains indicates if the given value is in the slice
|
||||
func (s *Uint8Slicer) Contains(matcher uint8) bool {
|
||||
result := false
|
||||
for _, elem := range s.slice {
|
||||
if elem == matcher {
|
||||
result = true
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Length returns the number of elements in the slice
|
||||
func (s *Uint8Slicer) Length() int {
|
||||
return len(s.slice)
|
||||
}
|
||||
|
||||
// Clear all elements in the slice
|
||||
func (s *Uint8Slicer) Clear() {
|
||||
s.slice = []uint8{}
|
||||
}
|
||||
|
||||
// Deduplicate removes duplicate values from the slice
|
||||
func (s *Uint8Slicer) Deduplicate() {
|
||||
|
||||
result := &Uint8Slicer{}
|
||||
|
||||
for _, elem := range s.slice {
|
||||
if !result.Contains(elem) {
|
||||
result.Add(elem)
|
||||
}
|
||||
}
|
||||
|
||||
s.slice = result.AsSlice()
|
||||
}
|
||||
|
||||
// Join returns a string with the slicer elements separated by the given separator
|
||||
func (s *Uint8Slicer) Join(separator string) string {
|
||||
var builder strings.Builder
|
||||
|
||||
// Shortcut no elements
|
||||
if len(s.slice) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Iterate over length - 1
|
||||
index := 0
|
||||
for index = 0; index < len(s.slice)-1; index++ {
|
||||
builder.WriteString(fmt.Sprintf("%v%s", s.slice[index], separator))
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("%v", s.slice[index]))
|
||||
result := builder.String()
|
||||
return result
|
||||
}
|
||||
|
||||
// Sort the slice values
|
||||
func (s *Uint8Slicer) Sort() {
|
||||
sort.Slice(s.slice, func(i, j int) bool { return s.slice[i] < s.slice[j] })
|
||||
}
|
||||
Reference in New Issue
Block a user