Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# **ANGoLS** Changes

## 0.8.0 (alpha 1) - 27th August 2025

* added generic function `func CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, fn func(input_item N) N) (result_slice []N)`;
* added generic function `func EqualSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []int) bool`;
* added generic function `func SelectSliceOfUInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []int) bool`;


## 0.7.0 - 27th August 2025

* 0.7.0
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func CollectSlice(input_slice any, fn func(input_item any) (any, error)) (any, e

func CollectSliceOfInt(input_slice []int, fn func(input_item int) int) (result_slice []int)

func CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, fn func(input_item N) N) (result_slice []N)

func CollectSliceOfFloat64(input_slice []float64, fn func(input_item float64) float64) (result_slice []float64)

func CollectSliceOfString(input_slice []string, fn func(input_item string) string) (result_slice []string)
Expand All @@ -100,6 +102,8 @@ func EqualSliceOfInt(lhs, rhs []int) bool

func EqualSliceOfUInt(lhs, rhs []uint) bool

func EqualSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []int) bool

func EqualSliceOfFloat64(lhs, rhs []float64) bool

func EqualSliceOfString(lhs, rhs []string) bool
Expand Down Expand Up @@ -130,6 +134,8 @@ func SelectSliceOfInt(input_slice []int, selector func(index int, input_item int

func SelectSliceOfUInt(input_slice []uint, selector func(index int, input_item uint) (bool, error)) ([]uint, error)

func SelectSliceOfUInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, selector func(index int, input_item N) (bool, error)) ([]N, error)

func SelectSliceOfString(input_slice []string, selector func(index int, input_item string) (bool, error)) ([]string, error)
```

Expand Down
17 changes: 16 additions & 1 deletion slices/collect_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*
* Created: 1st March 2019
* Updated: 24th February 2025
* Updated: 27th August 2025
*/

package slices
Expand Down Expand Up @@ -67,6 +67,21 @@ func CollectSliceOfInt(input_slice []int, fn func(input_item int) int) (result_s
return
}

// CollectSliceOfInteger
func CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, fn func(input_item N) N) (result_slice []N) {

result_slice = make([]N, len(input_slice))

for i, v := range input_slice {

result := fn(v)

result_slice[i] = result
}

return
}

// CollectSliceOfFloat64
func CollectSliceOfFloat64(input_slice []float64, fn func(input_item float64) float64) (result_slice []float64) {

Expand Down
49 changes: 49 additions & 0 deletions slices/collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,55 @@ func Test_CollectSliceOfInt_1(t *testing.T) {
}
}

func Test_CollectSliceOfInteger_WITH_int(t *testing.T) {

fn := func(input int) int {

if input < 0 {

return -input
}

return input
}

input_slice := []int{-1, 0, -2, 3}
expected := []int{1, 0, 2, 3}
actual := slices.CollectSliceOfInteger(input_slice, fn)

if !slices.EqualSliceOfInt(expected, actual) {

t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected)
}

if !slices.EqualSlice(expected, actual) {

t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected)
}
}

func Test_CollectSliceOfInteger_WITH_uint(t *testing.T) {

fn := func(input uint) uint {

return input * 2
}

input_slice := []uint{1, 0, 2, 3}
expected := []uint{2, 0, 4, 6}
actual := slices.CollectSliceOfInteger(input_slice, fn)

if !slices.EqualSliceOfUInt(expected, actual) {

t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected)
}

if !slices.EqualSlice(expected, actual) {

t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected)
}
}

func Test_CollectSliceOfFloat64_1(t *testing.T) {

fn := func(input float64) float64 {
Expand Down
24 changes: 23 additions & 1 deletion slices/equal_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*
* Created: 1st March 2019
* Updated: 24th February 2025
* Updated: 27th August 2025
*/

package slices
Expand Down Expand Up @@ -60,6 +60,28 @@ func EqualSliceOfUInt(lhs, rhs []uint) bool {
}
}

func EqualSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []int) bool {

len_l := len(lhs)
len_r := len(rhs)

if len_l != len_r {

return false
} else {

for i := 0; len_l != i; i++ {

if lhs[i] != rhs[i] {

return false
}
}

return true
}
}

func EqualSliceOfFloat64(lhs, rhs []float64) bool {

len_l := len(lhs)
Expand Down
24 changes: 24 additions & 0 deletions slices/select_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ func SelectSliceOfUInt(input_slice []uint, selector func(index int, input_item u
return result[0:result_len], nil
}

func SelectSliceOfUInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, selector func(index int, input_item N) (bool, error)) ([]N, error) {

input_len := len(input_slice)
result := make([]N, input_len)
result_len := 0

for i, v := range input_slice {

selected, err := selector(i, v)
if err != nil {

return nil, err
}

if selected {

result[result_len] = v
result_len++
}
}

return result[0:result_len], nil
}

func SelectSliceOfString(input_slice []string, selector func(index int, input_item string) (bool, error)) ([]string, error) {

input_len := len(input_slice)
Expand Down
4 changes: 2 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import "github.com/synesissoftware/ver2go"

const (
VersionMajor uint16 = 0
VersionMinor uint16 = 7
VersionMinor uint16 = 8
VersionPatch uint16 = 0
VersionAB uint16 = 0xFFFF
VersionAB uint16 = 0x4001
Version uint64 = (uint64(VersionMajor) << 48) + (uint64(VersionMinor) << 32) + (uint64(VersionPatch) << 16) + (uint64(VersionAB) << 0)
)

Expand Down
8 changes: 4 additions & 4 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

const (
Expected_VersionMajor uint16 = 0
Expected_VersionMinor uint16 = 7
Expected_VersionMinor uint16 = 8
Expected_VersionPatch uint16 = 0
Expected_VersionAB uint16 = 0xFFFF
Expected_VersionAB uint16 = 0x4001
)

func Test_Version_Elements(t *testing.T) {
Expand All @@ -22,9 +22,9 @@ func Test_Version_Elements(t *testing.T) {
}

func Test_Version(t *testing.T) {
require.Equal(t, uint64(0x0000_0007_0000_FFFF), angols.Version)
require.Equal(t, uint64(0x0000_0008_0000_4001), angols.Version)
}

func Test_Version_String(t *testing.T) {
require.Equal(t, "0.7.0", angols.VersionString())
require.Equal(t, "0.8.0-alpha1", angols.VersionString())
}
Loading