Skip to content

Commit cb19b34

Browse files
committed
Initial Commit
1 parent 0aba616 commit cb19b34

23 files changed

+936
-2
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
1-
# slicer
2-
Utility class for handling slices
1+
2+
<div style="text-align:center; width:400px"><img src="logo.png"/></div>
3+
4+
Utility class for handling slices.
5+
6+
## Install
7+
8+
`go get -u github.com/leaanthony/slicer`
9+
10+
## Quick Start
11+
12+
```
13+
import "github.com/leaanthony/slicer"
14+
15+
func test() {
16+
s := slicer.String()
17+
s.Add("one")
18+
s.Add("two")
19+
s.AddSlice([]string{"three","four"})
20+
fmt.Printf("My slice = %+v\n", s.AsSlice())
21+
22+
t := slicer.String()
23+
t.Add("zero")
24+
t.AddSlicer(s)
25+
fmt.Printf("My slice = %+v\n", t.AsSlice())
26+
}
27+
```
28+
29+
## Available slicers
30+
31+
- Int
32+
- Int8
33+
- Int16
34+
- Int32
35+
- Float32
36+
- Float64
37+
- String
38+
- Bool
39+
- Interface
40+

bool.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// BoolSlicer handles slices of bools
5+
type BoolSlicer struct {
6+
slice []bool
7+
}
8+
9+
// Bool creates a new BoolSlicer
10+
func Bool() *BoolSlicer {
11+
return &BoolSlicer{}
12+
}
13+
14+
// Add a bool value to the slicer
15+
func (s *BoolSlicer) Add(value bool) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a bool slice to the slicer
20+
func (s *BoolSlicer) AddSlice(value []bool) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *BoolSlicer) AsSlice() []bool {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a BoolSlicer to the slicer
30+
func (s *BoolSlicer) AddSlicer(value *BoolSlicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

float32.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// Float32Slicer handles slices of float32s
5+
type Float32Slicer struct {
6+
slice []float32
7+
}
8+
9+
// Float32 creates a new Float32Slicer
10+
func Float32() *Float32Slicer {
11+
return &Float32Slicer{}
12+
}
13+
14+
// Add a float32 value to the slicer
15+
func (s *Float32Slicer) Add(value float32) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a float32 slice to the slicer
20+
func (s *Float32Slicer) AddSlice(value []float32) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *Float32Slicer) AsSlice() []float32 {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a Float32Slicer to the slicer
30+
func (s *Float32Slicer) AddSlicer(value *Float32Slicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

float64.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// Float64Slicer handles slices of float64s
5+
type Float64Slicer struct {
6+
slice []float64
7+
}
8+
9+
// Float64 creates a new Float64Slicer
10+
func Float64() *Float64Slicer {
11+
return &Float64Slicer{}
12+
}
13+
14+
// Add a float64 value to the slicer
15+
func (s *Float64Slicer) Add(value float64) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a float64 slice to the slicer
20+
func (s *Float64Slicer) AddSlice(value []float64) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *Float64Slicer) AsSlice() []float64 {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a Float64Slicer to the slicer
30+
func (s *Float64Slicer) AddSlicer(value *Float64Slicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module github.com/leaanthony/slicer

int.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// IntSlicer handles slices of ints
5+
type IntSlicer struct {
6+
slice []int
7+
}
8+
9+
// Int creates a new IntSlicer
10+
func Int() *IntSlicer {
11+
return &IntSlicer{}
12+
}
13+
14+
// Add a int value to the slicer
15+
func (s *IntSlicer) Add(value int) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a int slice to the slicer
20+
func (s *IntSlicer) AddSlice(value []int) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *IntSlicer) AsSlice() []int {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a IntSlicer to the slicer
30+
func (s *IntSlicer) AddSlicer(value *IntSlicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

int16.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// Int16Slicer handles slices of int16s
5+
type Int16Slicer struct {
6+
slice []int16
7+
}
8+
9+
// Int16 creates a new Int16Slicer
10+
func Int16() *Int16Slicer {
11+
return &Int16Slicer{}
12+
}
13+
14+
// Add a int16 value to the slicer
15+
func (s *Int16Slicer) Add(value int16) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a int16 slice to the slicer
20+
func (s *Int16Slicer) AddSlice(value []int16) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *Int16Slicer) AsSlice() []int16 {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a Int16Slicer to the slicer
30+
func (s *Int16Slicer) AddSlicer(value *Int16Slicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

int32.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// Int32Slicer handles slices of int32s
5+
type Int32Slicer struct {
6+
slice []int32
7+
}
8+
9+
// Int32 creates a new Int32Slicer
10+
func Int32() *Int32Slicer {
11+
return &Int32Slicer{}
12+
}
13+
14+
// Add a int32 value to the slicer
15+
func (s *Int32Slicer) Add(value int32) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a int32 slice to the slicer
20+
func (s *Int32Slicer) AddSlice(value []int32) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *Int32Slicer) AsSlice() []int32 {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a Int32Slicer to the slicer
30+
func (s *Int32Slicer) AddSlicer(value *Int32Slicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

int64.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// Int64Slicer handles slices of int64s
5+
type Int64Slicer struct {
6+
slice []int64
7+
}
8+
9+
// Int64 creates a new Int64Slicer
10+
func Int64() *Int64Slicer {
11+
return &Int64Slicer{}
12+
}
13+
14+
// Add a int64 value to the slicer
15+
func (s *Int64Slicer) Add(value int64) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a int64 slice to the slicer
20+
func (s *Int64Slicer) AddSlice(value []int64) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *Int64Slicer) AsSlice() []int64 {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a Int64Slicer to the slicer
30+
func (s *Int64Slicer) AddSlicer(value *Int64Slicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

int8.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Package slicer cotains utility classes for handling slices
2+
package slicer
3+
4+
// Int8Slicer handles slices of int8s
5+
type Int8Slicer struct {
6+
slice []int8
7+
}
8+
9+
// Int8 creates a new Int8Slicer
10+
func Int8() *Int8Slicer {
11+
return &Int8Slicer{}
12+
}
13+
14+
// Add a int8 value to the slicer
15+
func (s *Int8Slicer) Add(value int8) {
16+
s.slice = append(s.slice, value)
17+
}
18+
19+
// AddSlice adds a int8 slice to the slicer
20+
func (s *Int8Slicer) AddSlice(value []int8) {
21+
s.slice = append(s.slice, value...)
22+
}
23+
24+
// AsSlice returns the slice
25+
func (s *Int8Slicer) AsSlice() []int8 {
26+
return s.slice
27+
}
28+
29+
// AddSlicer appends a Int8Slicer to the slicer
30+
func (s *Int8Slicer) AddSlicer(value *Int8Slicer) {
31+
s.slice = append(s.slice, value.AsSlice()...)
32+
}

0 commit comments

Comments
 (0)