From b114123a8853538da757bf340d4cb7c61f6c95b0 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Fri, 6 Feb 2026 18:25:26 +1100 Subject: [PATCH 01/18] tidy --- slices/collect_slice.go | 5 +++-- slices/collect_test.go | 3 +-- strings/ascii_test.go | 1 + strings/chomps_test.go | 1 + strings/find_test.go | 3 ++- version_test.go | 3 ++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/slices/collect_slice.go b/slices/collect_slice.go index 2fbf6ce..2b5bb78 100644 --- a/slices/collect_slice.go +++ b/slices/collect_slice.go @@ -4,7 +4,7 @@ /* * Created: 1st March 2019 - * Updated: 27th November 2025 + * Updated: 6th February 2026 */ package slices @@ -67,7 +67,8 @@ func CollectSliceOfInt(input_slice []int, fn func(input_item int) int) (result_s return } -// CollectSliceOfInteger +// This function maps an input slice of []N an output slice of []N, where N +// is an integer type. 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)) diff --git a/slices/collect_test.go b/slices/collect_test.go index ae7086d..1f1f613 100644 --- a/slices/collect_test.go +++ b/slices/collect_test.go @@ -1,10 +1,9 @@ package slices_test import ( - "fmt" - "github.com/synesissoftware/ANGoLS/slices" + "fmt" "strconv" "strings" "testing" diff --git a/strings/ascii_test.go b/strings/ascii_test.go index ed5491d..bf119cd 100644 --- a/strings/ascii_test.go +++ b/strings/ascii_test.go @@ -6,6 +6,7 @@ package strings_test import ( strings "github.com/synesissoftware/ANGoLS/strings" + stegol "github.com/synesissoftware/STEGoL" stdstrings "strings" diff --git a/strings/chomps_test.go b/strings/chomps_test.go index e8f7b70..830af84 100644 --- a/strings/chomps_test.go +++ b/strings/chomps_test.go @@ -2,6 +2,7 @@ package strings_test import ( strings "github.com/synesissoftware/ANGoLS/strings" + stegol "github.com/synesissoftware/STEGoL" "testing" diff --git a/strings/find_test.go b/strings/find_test.go index f9fd146..224aa9d 100644 --- a/strings/find_test.go +++ b/strings/find_test.go @@ -1,9 +1,10 @@ package strings_test import ( - "github.com/stretchr/testify/require" strings "github.com/synesissoftware/ANGoLS/strings" + "github.com/stretchr/testify/require" + "testing" ) diff --git a/version_test.go b/version_test.go index bfad339..00a08ca 100644 --- a/version_test.go +++ b/version_test.go @@ -1,9 +1,10 @@ package angols_test import ( - "github.com/stretchr/testify/require" angols "github.com/synesissoftware/ANGoLS" + "github.com/stretchr/testify/require" + "testing" ) From d2ecc56142d001f4697715a1d7f868c7c309f6d9 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 05:59:59 +1100 Subject: [PATCH 02/18] ~ fixed `EqualSliceOfInteger[]()` return type; + added unit-tests for equal and select --- slices/equal_slice.go | 2 +- slices/equal_test.go | 197 ++++++++++++++++++++++++++++++ slices/select_test.go | 276 ++++++++++++++++++++++++++++++++++++++++++ version.go | 4 +- version_test.go | 6 +- 5 files changed, 479 insertions(+), 6 deletions(-) create mode 100644 slices/equal_test.go create mode 100644 slices/select_test.go diff --git a/slices/equal_slice.go b/slices/equal_slice.go index 128e685..6e5a155 100644 --- a/slices/equal_slice.go +++ b/slices/equal_slice.go @@ -60,7 +60,7 @@ 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 EqualSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []N) bool { len_l := len(lhs) len_r := len(rhs) diff --git a/slices/equal_test.go b/slices/equal_test.go new file mode 100644 index 0000000..1ed1913 --- /dev/null +++ b/slices/equal_test.go @@ -0,0 +1,197 @@ +package slices_test + +import ( + "github.com/synesissoftware/ANGoLS/slices" + + "github.com/stretchr/testify/assert" + + "testing" +) + +func Test_EqualSliceOfInt(t *testing.T) { + + { + assert.True(t, slices.EqualSliceOfInt([]int{}, []int{})) + assert.True(t, slices.EqualSliceOfInt([]int{1}, []int{1})) + assert.False(t, slices.EqualSliceOfInt([]int{1}, []int{2})) + + assert.True(t, slices.EqualSliceOfInt([]int{1, 2, 3, 4}, []int{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInt([]int{1, 2, 3, 4}, []int{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInt([]int{1, 2, 3, 4, 5}[:4], []int{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]int{}, []int{})) + assert.True(t, slices.EqualSliceOfInteger([]int{1}, []int{1})) + assert.False(t, slices.EqualSliceOfInteger([]int{1}, []int{2})) + + assert.True(t, slices.EqualSliceOfInteger([]int{1, 2, 3, 4}, []int{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]int{1, 2, 3, 4}, []int{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]int{1, 2, 3, 4, 5}[:4], []int{1, 2, 3, 4, 6}[:4])) + } +} + +func Test_EqualSliceOfUint(t *testing.T) { + + { + assert.True(t, slices.EqualSliceOfUInt([]uint{}, []uint{})) + assert.True(t, slices.EqualSliceOfUInt([]uint{1}, []uint{1})) + assert.False(t, slices.EqualSliceOfUInt([]uint{1}, []uint{2})) + + assert.True(t, slices.EqualSliceOfUInt([]uint{1, 2, 3, 4}, []uint{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfUInt([]uint{1, 2, 3, 4}, []uint{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfUInt([]uint{1, 2, 3, 4, 5}[:4], []uint{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uint{}, []uint{})) + assert.True(t, slices.EqualSliceOfInteger([]uint{1}, []uint{1})) + assert.False(t, slices.EqualSliceOfInteger([]uint{1}, []uint{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uint{1, 2, 3, 4}, []uint{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uint{1, 2, 3, 4}, []uint{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uint{1, 2, 3, 4, 5}[:4], []uint{1, 2, 3, 4, 6}[:4])) + } +} + +func Test_EqualSliceOfInteger(t *testing.T) { + + { + assert.True(t, slices.EqualSliceOfInteger([]int{}, []int{})) + assert.True(t, slices.EqualSliceOfInteger([]int{1}, []int{1})) + assert.False(t, slices.EqualSliceOfInteger([]int{1}, []int{2})) + + assert.True(t, slices.EqualSliceOfInteger([]int{1, 2, 3, 4}, []int{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]int{1, 2, 3, 4}, []int{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]int{1, 2, 3, 4, 5}[:4], []int{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uint{}, []uint{})) + assert.True(t, slices.EqualSliceOfInteger([]uint{1}, []uint{1})) + assert.False(t, slices.EqualSliceOfInteger([]uint{1}, []uint{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uint{1, 2, 3, 4}, []uint{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uint{1, 2, 3, 4}, []uint{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uint{1, 2, 3, 4, 5}[:4], []uint{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]int8{}, []int8{})) + assert.True(t, slices.EqualSliceOfInteger([]int8{1}, []int8{1})) + assert.False(t, slices.EqualSliceOfInteger([]int8{1}, []int8{2})) + + assert.True(t, slices.EqualSliceOfInteger([]int8{1, 2, 3, 4}, []int8{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]int8{1, 2, 3, 4}, []int8{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]int8{1, 2, 3, 4, 5}[:4], []int8{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uint8{}, []uint8{})) + assert.True(t, slices.EqualSliceOfInteger([]uint8{1}, []uint8{1})) + assert.False(t, slices.EqualSliceOfInteger([]uint8{1}, []uint8{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uint8{1, 2, 3, 4}, []uint8{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uint8{1, 2, 3, 4}, []uint8{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uint8{1, 2, 3, 4, 5}[:4], []uint8{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]int16{}, []int16{})) + assert.True(t, slices.EqualSliceOfInteger([]int16{1}, []int16{1})) + assert.False(t, slices.EqualSliceOfInteger([]int16{1}, []int16{2})) + + assert.True(t, slices.EqualSliceOfInteger([]int16{1, 2, 3, 4}, []int16{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]int16{1, 2, 3, 4}, []int16{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]int16{1, 2, 3, 4, 5}[:4], []int16{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uint16{}, []uint16{})) + assert.True(t, slices.EqualSliceOfInteger([]uint16{1}, []uint16{1})) + assert.False(t, slices.EqualSliceOfInteger([]uint16{1}, []uint16{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uint16{1, 2, 3, 4}, []uint16{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uint16{1, 2, 3, 4}, []uint16{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uint16{1, 2, 3, 4, 5}[:4], []uint16{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]int32{}, []int32{})) + assert.True(t, slices.EqualSliceOfInteger([]int32{1}, []int32{1})) + assert.False(t, slices.EqualSliceOfInteger([]int32{1}, []int32{2})) + + assert.True(t, slices.EqualSliceOfInteger([]int32{1, 2, 3, 4}, []int32{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]int32{1, 2, 3, 4}, []int32{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]int32{1, 2, 3, 4, 5}[:4], []int32{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uint32{}, []uint32{})) + assert.True(t, slices.EqualSliceOfInteger([]uint32{1}, []uint32{1})) + assert.False(t, slices.EqualSliceOfInteger([]uint32{1}, []uint32{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uint32{1, 2, 3, 4}, []uint32{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uint32{1, 2, 3, 4}, []uint32{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uint32{1, 2, 3, 4, 5}[:4], []uint32{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]int64{}, []int64{})) + assert.True(t, slices.EqualSliceOfInteger([]int64{1}, []int64{1})) + assert.False(t, slices.EqualSliceOfInteger([]int64{1}, []int64{2})) + + assert.True(t, slices.EqualSliceOfInteger([]int64{1, 2, 3, 4}, []int64{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]int64{1, 2, 3, 4}, []int64{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]int64{1, 2, 3, 4, 5}[:4], []int64{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uint64{}, []uint64{})) + assert.True(t, slices.EqualSliceOfInteger([]uint64{1}, []uint64{1})) + assert.False(t, slices.EqualSliceOfInteger([]uint64{1}, []uint64{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uint64{1, 2, 3, 4}, []uint64{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uint64{1, 2, 3, 4}, []uint64{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uint64{1, 2, 3, 4, 5}[:4], []uint64{1, 2, 3, 4, 6}[:4])) + } + + { + assert.True(t, slices.EqualSliceOfInteger([]uintptr{}, []uintptr{})) + assert.True(t, slices.EqualSliceOfInteger([]uintptr{1}, []uintptr{1})) + assert.False(t, slices.EqualSliceOfInteger([]uintptr{1}, []uintptr{2})) + + assert.True(t, slices.EqualSliceOfInteger([]uintptr{1, 2, 3, 4}, []uintptr{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfInteger([]uintptr{1, 2, 3, 4}, []uintptr{1, 2, 4, 3})) + + assert.True(t, slices.EqualSliceOfInteger([]uintptr{1, 2, 3, 4, 5}[:4], []uintptr{1, 2, 3, 4, 6}[:4])) + } +} + +func Test_EqualSliceOfString(t *testing.T) { + + { + assert.True(t, slices.EqualSliceOfString([]string{}, []string{})) + assert.True(t, slices.EqualSliceOfString([]string{"1"}, []string{"1"})) + assert.False(t, slices.EqualSliceOfString([]string{"1"}, []string{"2"})) + + assert.True(t, slices.EqualSliceOfString([]string{"1", "2", "3", "4"}, []string{"1", "2", "3", "4"})) + assert.False(t, slices.EqualSliceOfString([]string{"1", "2", "3", "4"}, []string{"1", "2", "4", "3"})) + + assert.True(t, slices.EqualSliceOfString([]string{"1", "2", "3", "4", "5"}[:4], []string{"1", "2", "3", "4", "6"}[:4])) + } +} diff --git a/slices/select_test.go b/slices/select_test.go new file mode 100644 index 0000000..da561c6 --- /dev/null +++ b/slices/select_test.go @@ -0,0 +1,276 @@ +package slices_test + +import ( + "github.com/synesissoftware/ANGoLS/slices" + + "github.com/stretchr/testify/assert" + + "testing" +) + +func Test_SelectSliceOfInt(t *testing.T) { + + { + input := []int{} + + { + r, _ := slices.SelectSliceOfInt( + input, + func(_, _ int) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []int{}, r) + } + { + r, _ := slices.SelectSliceOfInt( + input, + func(_, _ int) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []int{}, r) + } + } + + { + input := []int{1} + + { + r, _ := slices.SelectSliceOfInt( + input, + func(_, _ int) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []int{1}, r) + } + { + r, _ := slices.SelectSliceOfInt( + input, + func(_, _ int) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []int{}, r) + } + } + + { + input := []int{1, 2, 3, 4, 5, 6} + + { + r, _ := slices.SelectSliceOfInt( + input, + func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, + ) + + assert.Equal(t, []int{1, 3, 5}, r) + } + { + r, _ := slices.SelectSliceOfInt( + input, + func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, + ) + + assert.Equal(t, []int{2, 4, 6}, r) + } + } +} + +func Test_SelectSliceOfUInt(t *testing.T) { + + { + input := []uint{} + + { + r, _ := slices.SelectSliceOfUInt( + input, + func(_ int, _ uint) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []uint{}, r) + } + { + r, _ := slices.SelectSliceOfUInt( + input, + func(_ int, _ uint) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []uint{}, r) + } + } + + { + input := []uint{1} + + { + r, _ := slices.SelectSliceOfUInt( + input, + func(_ int, _ uint) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []uint{1}, r) + } + { + r, _ := slices.SelectSliceOfUInt( + input, + func(_ int, _ uint) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []uint{}, r) + } + } + + { + input := []uint{1, 2, 3, 4, 5, 6} + + { + r, _ := slices.SelectSliceOfUInt( + input, + func(_ int, input_item uint) (bool, error) { return 0 != (input_item % 2), nil }, + ) + + assert.Equal(t, []uint{1, 3, 5}, r) + } + { + r, _ := slices.SelectSliceOfUInt( + input, + func(_ int, input_item uint) (bool, error) { return 0 == (input_item % 2), nil }, + ) + + assert.Equal(t, []uint{2, 4, 6}, r) + } + } +} + +func Test_SelectSliceOfInteger(t *testing.T) { + + // int + { + { + input := []int{} + + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []int{}, r) + } + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []int{}, r) + } + } + + { + input := []int{1} + + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []int{1}, r) + } + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []int{}, r) + } + } + + { + input := []int{1, 2, 3, 4, 5, 6} + + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, + ) + + assert.Equal(t, []int{1, 3, 5}, r) + } + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, + ) + + assert.Equal(t, []int{2, 4, 6}, r) + } + } + } + + // int + { + { + input := []int{} + + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []int{}, r) + } + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []int{}, r) + } + } + + { + input := []int{1} + + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []int{1}, r) + } + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, _ int) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []int{}, r) + } + } + + { + input := []int{1, 2, 3, 4, 5, 6} + + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, + ) + + assert.Equal(t, []int{1, 3, 5}, r) + } + { + r, _ := slices.SelectSliceOfUInteger( + input, + func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, + ) + + assert.Equal(t, []int{2, 4, 6}, r) + } + } + } +} diff --git a/version.go b/version.go index de574b7..fa1b750 100644 --- a/version.go +++ b/version.go @@ -4,7 +4,7 @@ /* * Created: 1st March 2019 - * Updated: 3rd January 2025 + * Updated: 6th February 2026 */ package angols @@ -14,7 +14,7 @@ import "github.com/synesissoftware/ver2go" const ( VersionMajor uint16 = 0 VersionMinor uint16 = 9 - VersionPatch uint16 = 0 + VersionPatch uint16 = 1 VersionAB uint16 = 0xFFFF Version uint64 = (uint64(VersionMajor) << 48) + (uint64(VersionMinor) << 32) + (uint64(VersionPatch) << 16) + (uint64(VersionAB) << 0) ) diff --git a/version_test.go b/version_test.go index 00a08ca..8944a74 100644 --- a/version_test.go +++ b/version_test.go @@ -11,7 +11,7 @@ import ( const ( Expected_VersionMajor uint16 = 0 Expected_VersionMinor uint16 = 9 - Expected_VersionPatch uint16 = 0 + Expected_VersionPatch uint16 = 1 Expected_VersionAB uint16 = 0xFFFF ) @@ -23,9 +23,9 @@ func Test_Version_Elements(t *testing.T) { } func Test_Version(t *testing.T) { - require.Equal(t, uint64(0x0000_0009_0000_FFFF), angols.Version) + require.Equal(t, uint64(0x0000_0009_0001_FFFF), angols.Version) } func Test_Version_String(t *testing.T) { - require.Equal(t, "0.9.0", angols.VersionString()) + require.Equal(t, "0.9.1", angols.VersionString()) } From d89969d995e0307d4919d3fa7c619e5113d7dc21 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 06:12:43 +1100 Subject: [PATCH 03/18] 0.9.1 --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d9fa3d9..28db9b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # **ANGoLS** Changes +## 0.9.1 - 7th February 2026 + +* fixed `EqualSliceOfInteger[]()` return type; +* added unit-tests for equal and select; + + ## 0.9.0 - 3rd January 2026 * 0.9.0 From 624927c7f3cdb2109b5ffd580266baaf2b4c7c93 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 06:35:58 +1100 Subject: [PATCH 04/18] breaking changes to names, correcting from `UInt` to `Uint` --- README.md | 10 +++++----- select_test.go | 12 ++++++------ slices/collect_test.go | 6 +++--- slices/equal_slice.go | 6 +++--- slices/equal_test.go | 12 ++++++------ slices/generate_slice.go | 6 +++--- slices/select_slice.go | 8 ++++---- slices/select_test.go | 38 +++++++++++++++++++------------------- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 947116e..f6b1712 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ func CollectSliceIntoStringSlice[T any](input_slice []T, fn func(input_item *T) func EqualSliceOfInt(lhs, rhs []int) bool -func EqualSliceOfUInt(lhs, rhs []uint) 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 @@ -120,9 +120,9 @@ func EqualSlice(lhs, rhs any) bool // values with the given generator (which may be nil) func GenerateSliceOfInt(size int, generator func(index int) (result int, err error)) (result []int, err error) -// GenerateSliceOfUInt() creates a slice of a given size and populates its +// GenerateSliceOfUint() creates a slice of a given size and populates its // values with the given generator (which may be nil) -func GenerateSliceOfUInt(size int, generator func(index int) (result uint, err error)) (result []uint, err error) +func GenerateSliceOfUint(size int, generator func(index int) (result uint, err error)) (result []uint, err error) // GenerateSliceOfString() creates a slice of a given size and populates its // values with the given generator (which may be nil) @@ -134,9 +134,9 @@ func GenerateSliceOfString(size int, generator func(index int) (result string, e func SelectSliceOfInt(input_slice []int, selector func(index int, input_item int) (bool, error)) ([]int, error) -func SelectSliceOfUInt(input_slice []uint, selector func(index int, input_item uint) (bool, error)) ([]uint, error) +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 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) ``` diff --git a/select_test.go b/select_test.go index 94fcfe6..1c5dcdc 100644 --- a/select_test.go +++ b/select_test.go @@ -37,23 +37,23 @@ func Test_SelectSliceOfInt_1(t *testing.T) { } } -func Test_SelectSliceOfUInt_1(t *testing.T) { +func Test_SelectSliceOfUint_1(t *testing.T) { - input, err := slices.GenerateSliceOfUInt(10, func(index int) (uint, error) { return uint(index), nil }) + input, err := slices.GenerateSliceOfUint(10, func(index int) (uint, error) { return uint(index), nil }) if err != nil { - t.Errorf("GenerateSliceOfUInt() failed: %v\n", err) + t.Errorf("GenerateSliceOfUint() failed: %v\n", err) } else { - actual, err := slices.SelectSliceOfUInt(input, func(index int, value uint) (bool, error) { return 0 == (value % 2), nil }) + actual, err := slices.SelectSliceOfUint(input, func(index int, value uint) (bool, error) { return 0 == (value % 2), nil }) if err != nil { - t.Errorf("SelectSliceOfUInt() failed: %v\n", err) + t.Errorf("SelectSliceOfUint() failed: %v\n", err) } else { expected := []uint{0, 2, 4, 6, 8} - if !slices.EqualSliceOfUInt(expected, actual) { + if !slices.EqualSliceOfUint(expected, actual) { t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) } diff --git a/slices/collect_test.go b/slices/collect_test.go index 1f1f613..35748f0 100644 --- a/slices/collect_test.go +++ b/slices/collect_test.go @@ -120,7 +120,7 @@ func Test_CollectSliceOfInteger_WITH_uint(t *testing.T) { expected := []uint{2, 0, 4, 6} actual := slices.CollectSliceOfInteger(input_slice, fn) - if !slices.EqualSliceOfUInt(expected, actual) { + if !slices.EqualSliceOfUint(expected, actual) { t.Errorf("actual value '%v' does not equal expected value '%v'", actual, expected) } @@ -204,8 +204,8 @@ func Benchmark_equal_ints_by_EqualSlice(b *testing.B) { func Benchmark_equal_uints_by_EqualSlice(b *testing.B) { fn := func(index int) (uint, error) { return uint(index), nil } - ints_1, _ := slices.GenerateSliceOfUInt(int_equal_size, fn) - ints_2, _ := slices.GenerateSliceOfUInt(int_equal_size, fn) + ints_1, _ := slices.GenerateSliceOfUint(int_equal_size, fn) + ints_2, _ := slices.GenerateSliceOfUint(int_equal_size, fn) for i := 0; i != int_equal_iterations; i++ { diff --git a/slices/equal_slice.go b/slices/equal_slice.go index 6e5a155..931bdf9 100644 --- a/slices/equal_slice.go +++ b/slices/equal_slice.go @@ -1,10 +1,10 @@ -// Copyright 2019-2025 Matthew Wilson and Synesis Information Systems. All +// Copyright 2019-2026 Matthew Wilson and Synesis Information Systems. All // rights reserved. Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. /* * Created: 1st March 2019 - * Updated: 27th August 2025 + * Updated: 7th February 2026 */ package slices @@ -38,7 +38,7 @@ func EqualSliceOfInt(lhs, rhs []int) bool { } } -func EqualSliceOfUInt(lhs, rhs []uint) bool { +func EqualSliceOfUint(lhs, rhs []uint) bool { len_l := len(lhs) len_r := len(rhs) diff --git a/slices/equal_test.go b/slices/equal_test.go index 1ed1913..e599bfa 100644 --- a/slices/equal_test.go +++ b/slices/equal_test.go @@ -36,14 +36,14 @@ func Test_EqualSliceOfInt(t *testing.T) { func Test_EqualSliceOfUint(t *testing.T) { { - assert.True(t, slices.EqualSliceOfUInt([]uint{}, []uint{})) - assert.True(t, slices.EqualSliceOfUInt([]uint{1}, []uint{1})) - assert.False(t, slices.EqualSliceOfUInt([]uint{1}, []uint{2})) + assert.True(t, slices.EqualSliceOfUint([]uint{}, []uint{})) + assert.True(t, slices.EqualSliceOfUint([]uint{1}, []uint{1})) + assert.False(t, slices.EqualSliceOfUint([]uint{1}, []uint{2})) - assert.True(t, slices.EqualSliceOfUInt([]uint{1, 2, 3, 4}, []uint{1, 2, 3, 4})) - assert.False(t, slices.EqualSliceOfUInt([]uint{1, 2, 3, 4}, []uint{1, 2, 4, 3})) + assert.True(t, slices.EqualSliceOfUint([]uint{1, 2, 3, 4}, []uint{1, 2, 3, 4})) + assert.False(t, slices.EqualSliceOfUint([]uint{1, 2, 3, 4}, []uint{1, 2, 4, 3})) - assert.True(t, slices.EqualSliceOfUInt([]uint{1, 2, 3, 4, 5}[:4], []uint{1, 2, 3, 4, 6}[:4])) + assert.True(t, slices.EqualSliceOfUint([]uint{1, 2, 3, 4, 5}[:4], []uint{1, 2, 3, 4, 6}[:4])) } { diff --git a/slices/generate_slice.go b/slices/generate_slice.go index 4862676..37b6827 100644 --- a/slices/generate_slice.go +++ b/slices/generate_slice.go @@ -1,10 +1,10 @@ -// Copyright 2019-2025 Matthew Wilson and Synesis Information Systems. All +// Copyright 2019-2026 Matthew Wilson and Synesis Information Systems. All // rights reserved. Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. /* * Created: 1st March 2019 - * Updated: 27th November 2025 + * Updated: 7th February 2026 */ package slices @@ -51,7 +51,7 @@ func GenerateSliceOfInt(size int, generator func(index int) (result int, err err // Creates a slice of a given size and populates its values with the given // generator (which may be nil). -func GenerateSliceOfUInt(size int, generator func(index int) (result uint, err error)) (result []uint, err error) { +func GenerateSliceOfUint(size int, generator func(index int) (result uint, err error)) (result []uint, err error) { result = make([]uint, size) diff --git a/slices/select_slice.go b/slices/select_slice.go index 86033fe..c871505 100644 --- a/slices/select_slice.go +++ b/slices/select_slice.go @@ -1,10 +1,10 @@ -// Copyright 2019-2025 Matthew Wilson and Synesis Information Systems. All +// Copyright 2019-2026 Matthew Wilson and Synesis Information Systems. All // rights reserved. Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. /* * Created: 1st March 2019 - * Updated: 24th February 2025 + * Updated: 7th February 2026 */ package slices @@ -36,7 +36,7 @@ func SelectSliceOfInt(input_slice []int, selector func(index int, input_item int return result[0:result_len], nil } -func SelectSliceOfUInt(input_slice []uint, selector func(index int, input_item uint) (bool, error)) ([]uint, error) { +func SelectSliceOfUint(input_slice []uint, selector func(index int, input_item uint) (bool, error)) ([]uint, error) { input_len := len(input_slice) result := make([]uint, input_len) @@ -60,7 +60,7 @@ 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) { +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) diff --git a/slices/select_test.go b/slices/select_test.go index da561c6..671aa2f 100644 --- a/slices/select_test.go +++ b/slices/select_test.go @@ -74,13 +74,13 @@ func Test_SelectSliceOfInt(t *testing.T) { } } -func Test_SelectSliceOfUInt(t *testing.T) { +func Test_SelectSliceOfUint(t *testing.T) { { input := []uint{} { - r, _ := slices.SelectSliceOfUInt( + r, _ := slices.SelectSliceOfUint( input, func(_ int, _ uint) (bool, error) { return true, nil }, ) @@ -88,7 +88,7 @@ func Test_SelectSliceOfUInt(t *testing.T) { assert.Equal(t, []uint{}, r) } { - r, _ := slices.SelectSliceOfUInt( + r, _ := slices.SelectSliceOfUint( input, func(_ int, _ uint) (bool, error) { return false, nil }, ) @@ -101,7 +101,7 @@ func Test_SelectSliceOfUInt(t *testing.T) { input := []uint{1} { - r, _ := slices.SelectSliceOfUInt( + r, _ := slices.SelectSliceOfUint( input, func(_ int, _ uint) (bool, error) { return true, nil }, ) @@ -109,7 +109,7 @@ func Test_SelectSliceOfUInt(t *testing.T) { assert.Equal(t, []uint{1}, r) } { - r, _ := slices.SelectSliceOfUInt( + r, _ := slices.SelectSliceOfUint( input, func(_ int, _ uint) (bool, error) { return false, nil }, ) @@ -122,7 +122,7 @@ func Test_SelectSliceOfUInt(t *testing.T) { input := []uint{1, 2, 3, 4, 5, 6} { - r, _ := slices.SelectSliceOfUInt( + r, _ := slices.SelectSliceOfUint( input, func(_ int, input_item uint) (bool, error) { return 0 != (input_item % 2), nil }, ) @@ -130,7 +130,7 @@ func Test_SelectSliceOfUInt(t *testing.T) { assert.Equal(t, []uint{1, 3, 5}, r) } { - r, _ := slices.SelectSliceOfUInt( + r, _ := slices.SelectSliceOfUint( input, func(_ int, input_item uint) (bool, error) { return 0 == (input_item % 2), nil }, ) @@ -148,7 +148,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{} { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -156,7 +156,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{}, r) } { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -169,7 +169,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1} { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -177,7 +177,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1}, r) } { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -190,7 +190,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1, 2, 3, 4, 5, 6} { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, ) @@ -198,7 +198,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1, 3, 5}, r) } { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, ) @@ -214,7 +214,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{} { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -222,7 +222,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{}, r) } { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -235,7 +235,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1} { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -243,7 +243,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1}, r) } { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -256,7 +256,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1, 2, 3, 4, 5, 6} { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, ) @@ -264,7 +264,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1, 3, 5}, r) } { - r, _ := slices.SelectSliceOfUInteger( + r, _ := slices.SelectSliceOfUinteger( input, func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, ) From cea154b0d3fe40606d727c1fa1bd478fd4931f68 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 06:37:55 +1100 Subject: [PATCH 05/18] breaking changes to names, correcting from `UInt` to `Uint` --- README.md | 2 +- slices/select_slice.go | 2 +- slices/select_test.go | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f6b1712..0d4d715 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ 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 SelectSliceOfInteger[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) ``` diff --git a/slices/select_slice.go b/slices/select_slice.go index c871505..eedc82d 100644 --- a/slices/select_slice.go +++ b/slices/select_slice.go @@ -60,7 +60,7 @@ 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) { +func SelectSliceOfInteger[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) diff --git a/slices/select_test.go b/slices/select_test.go index 671aa2f..4b684c7 100644 --- a/slices/select_test.go +++ b/slices/select_test.go @@ -148,7 +148,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{} { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -156,7 +156,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{}, r) } { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -169,7 +169,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1} { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -177,7 +177,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1}, r) } { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -190,7 +190,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1, 2, 3, 4, 5, 6} { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, ) @@ -198,7 +198,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1, 3, 5}, r) } { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, ) @@ -214,7 +214,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{} { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -222,7 +222,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{}, r) } { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -235,7 +235,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1} { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return true, nil }, ) @@ -243,7 +243,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1}, r) } { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, _ int) (bool, error) { return false, nil }, ) @@ -256,7 +256,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { input := []int{1, 2, 3, 4, 5, 6} { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, ) @@ -264,7 +264,7 @@ func Test_SelectSliceOfInteger(t *testing.T) { assert.Equal(t, []int{1, 3, 5}, r) } { - r, _ := slices.SelectSliceOfUinteger( + r, _ := slices.SelectSliceOfInteger( input, func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, ) From c7b9d92a73e4f07b4017f6dbaf0022f9e8bf03ab Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 16:28:25 +1100 Subject: [PATCH 06/18] misc mods --- CHANGES.md | 5 +++++ TODO.md | 7 ++++--- slices/collect_test.go | 23 ++++++++++++++--------- strings/ascii_test.go | 12 ++++++++---- version.go | 8 ++++---- version_test.go | 10 +++++----- 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 28db9b5..0b4aa70 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ # **ANGoLS** Changes +## 0.10.0-alpha1 - 7th February 2026 + +* renamed `SelectSliceOfUinteger()` => `SelectSliceOfInteger()`; + + ## 0.9.1 - 7th February 2026 * fixed `EqualSliceOfInteger[]()` return type; diff --git a/TODO.md b/TODO.md index f26d4a7..6b0893f 100644 --- a/TODO.md +++ b/TODO.md @@ -11,9 +11,9 @@ recls for Go ## 0.9.x Items -* simplify `CollectSlice()`; -* add unit-testing for `slices` functions; -* enhance code coverage in unit-tests; +* ~~simplify `CollectSlice()`~~ - ✅; +* ~~add unit-testing for `slices` functions~~ - ✅; +* ~~enhance code coverage in unit-tests~~ - ✅; ## 0.10+ Items @@ -23,6 +23,7 @@ recls for Go * `GenerateSliceOfInteger[T]()`; * `SelectSlice[T]()`; * expand coverage of specific types for `EqualSlice[T]()`; +* enhance code coverage in unit-tests; ## 0.11+ Items diff --git a/slices/collect_test.go b/slices/collect_test.go index 35748f0..351e8cb 100644 --- a/slices/collect_test.go +++ b/slices/collect_test.go @@ -10,8 +10,7 @@ import ( ) const ( - int_equal_iterations = 100000 - int_equal_size = 100 + int_equal_size = 1_000 ) // Tests @@ -183,7 +182,9 @@ func Benchmark_equal_ints_by_EqualSliceOfInt(b *testing.B) { ints_1, _ := slices.GenerateSliceOfInt(int_equal_size, fn) ints_2, _ := slices.GenerateSliceOfInt(int_equal_size, fn) - for i := 0; i != int_equal_iterations; i++ { + b.ResetTimer() + + for b.Loop() { _ = slices.EqualSliceOfInt(ints_1, ints_2) } @@ -195,7 +196,9 @@ func Benchmark_equal_ints_by_EqualSlice(b *testing.B) { ints_1, _ := slices.GenerateSliceOfInt(int_equal_size, fn) ints_2, _ := slices.GenerateSliceOfInt(int_equal_size, fn) - for i := 0; i != int_equal_iterations; i++ { + b.ResetTimer() + + for b.Loop() { _ = slices.EqualSlice(ints_1, ints_2) } @@ -207,7 +210,9 @@ func Benchmark_equal_uints_by_EqualSlice(b *testing.B) { ints_1, _ := slices.GenerateSliceOfUint(int_equal_size, fn) ints_2, _ := slices.GenerateSliceOfUint(int_equal_size, fn) - for i := 0; i != int_equal_iterations; i++ { + b.ResetTimer() + + for b.Loop() { _ = slices.EqualSlice(ints_1, ints_2) } @@ -223,7 +228,7 @@ func Test_CollectSliceIntoStringSlice(t *testing.T) { "Maverick", } - result, err := slices.CollectSliceIntoStringSlice[Nickname](nicknames, func(input_item *Nickname) (string, error) { + result, err := slices.CollectSliceIntoStringSlice(nicknames, func(input_item *Nickname) (string, error) { return string(*input_item), nil }) @@ -248,7 +253,7 @@ func Test_CollectSliceIntoStringSlice_with_CaseTesting(t *testing.T) { "Maverick", } - result, err := slices.CollectSliceIntoStringSlice[Nickname](nicknames, func(input_item *Nickname) (string, error) { + result, err := slices.CollectSliceIntoStringSlice(nicknames, func(input_item *Nickname) (string, error) { return strings.ToUpper(string(*input_item)), nil }) @@ -271,7 +276,7 @@ func Test_CollectSliceIntoStringSlice_with_Ints(t *testing.T) { 3, } - result, err := slices.CollectSliceIntoStringSlice[int](values, func(input_item *int) (string, error) { + result, err := slices.CollectSliceIntoStringSlice(values, func(input_item *int) (string, error) { return strconv.Itoa(*input_item), nil }) @@ -296,7 +301,7 @@ func Test_CollectSliceIntoStringSlice_with_Fail(t *testing.T) { "Maverick", } - _, err := slices.CollectSliceIntoStringSlice[Nickname](nicknames, func(input_item *Nickname) (string, error) { + _, err := slices.CollectSliceIntoStringSlice(nicknames, func(input_item *Nickname) (string, error) { if strings.Contains(string(*input_item), "k") { return "", fmt.Errorf("invalid nickname: %s", *input_item) } diff --git a/strings/ascii_test.go b/strings/ascii_test.go index bf119cd..cb028d6 100644 --- a/strings/ascii_test.go +++ b/strings/ascii_test.go @@ -43,28 +43,32 @@ func Test_ASCIIToUpper(t *testing.T) { func Benchmark_ASCIIToLower(b *testing.B) { const s = "Hello, World!" - for i := 0; i < b.N; i++ { + + for b.Loop() { _ = strings.ASCIIToLower(s) } } func Benchmark_StringsToLower(b *testing.B) { const s = "Hello, World!" - for i := 0; i < b.N; i++ { + + for b.Loop() { _ = stdstrings.ToLower(s) } } func Benchmark_ASCIIToUpper(b *testing.B) { const s = "Hello, World!" - for i := 0; i < b.N; i++ { + + for b.Loop() { _ = strings.ASCIIToUpper(s) } } func Benchmark_StringsToUpper(b *testing.B) { const s = "Hello, World!" - for i := 0; i < b.N; i++ { + + for b.Loop() { _ = stdstrings.ToUpper(s) } } diff --git a/version.go b/version.go index fa1b750..9039645 100644 --- a/version.go +++ b/version.go @@ -4,7 +4,7 @@ /* * Created: 1st March 2019 - * Updated: 6th February 2026 + * Updated: 7th February 2026 */ package angols @@ -13,9 +13,9 @@ import "github.com/synesissoftware/ver2go" const ( VersionMajor uint16 = 0 - VersionMinor uint16 = 9 - VersionPatch uint16 = 1 - VersionAB uint16 = 0xFFFF + VersionMinor uint16 = 10 + VersionPatch uint16 = 0 + VersionAB uint16 = 0x4001 Version uint64 = (uint64(VersionMajor) << 48) + (uint64(VersionMinor) << 32) + (uint64(VersionPatch) << 16) + (uint64(VersionAB) << 0) ) diff --git a/version_test.go b/version_test.go index 8944a74..4cd2fd9 100644 --- a/version_test.go +++ b/version_test.go @@ -10,9 +10,9 @@ import ( const ( Expected_VersionMajor uint16 = 0 - Expected_VersionMinor uint16 = 9 - Expected_VersionPatch uint16 = 1 - Expected_VersionAB uint16 = 0xFFFF + Expected_VersionMinor uint16 = 10 + Expected_VersionPatch uint16 = 0 + Expected_VersionAB uint16 = 0x4001 ) func Test_Version_Elements(t *testing.T) { @@ -23,9 +23,9 @@ func Test_Version_Elements(t *testing.T) { } func Test_Version(t *testing.T) { - require.Equal(t, uint64(0x0000_0009_0001_FFFF), angols.Version) + require.Equal(t, uint64(0x0000_000A_0000_4001), angols.Version) } func Test_Version_String(t *testing.T) { - require.Equal(t, "0.9.1", angols.VersionString()) + require.Equal(t, "0.10.0-alpha1", angols.VersionString()) } From 782c827fb82482cf823f7f104225ba60be2b28fe Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:17:58 +1100 Subject: [PATCH 07/18] refactor: various `SelectSliceOfXxxx()` improvements --- CHANGES.md | 5 ++ slices/select_slice.go | 86 ++++++++------------------- slices/select_test.go | 132 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 146 insertions(+), 77 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0b4aa70..4c44645 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,11 @@ ## 0.10.0-alpha1 - 7th February 2026 * renamed `SelectSliceOfUinteger()` => `SelectSliceOfInteger()`; +* simplified implementation of `SelectSliceOfInteger[T]()`; +* added unit-tests for `SelectSliceOfInt()` and `SelectSliceOfString()`; +* refactored `SelectSliceOfInt()` in terms of `SelectSliceOfInteger[T]()`; +* refactored `SelectSliceOfUint()` in terms of `SelectSliceOfInteger[T]()`; +* simplified implementation of `SelectSliceOfString()`; ## 0.9.1 - 7th February 2026 diff --git a/slices/select_slice.go b/slices/select_slice.go index eedc82d..578ce2d 100644 --- a/slices/select_slice.go +++ b/slices/select_slice.go @@ -12,100 +12,64 @@ package slices // ///////////////////////////////////////////////////////////////////////// // Select* +// Selects elements of an input slice of []int to an output slice of []int, +// according to the given selector function. func SelectSliceOfInt(input_slice []int, selector func(index int, input_item int) (bool, error)) ([]int, error) { - input_len := len(input_slice) - result := make([]int, 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 + return SelectSliceOfInteger(input_slice, selector) } +// Selects elements of an input slice of []uint to an output slice of +// []uint, according to the given selector function. func SelectSliceOfUint(input_slice []uint, selector func(index int, input_item uint) (bool, error)) ([]uint, error) { - input_len := len(input_slice) - result := make([]uint, 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 + return SelectSliceOfInteger(input_slice, selector) } +// Selects elements of an input slice of []N to an output slice of []N, +// according to the given selector function. func SelectSliceOfInteger[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 + r := make([]N, 0, len(input_slice)) for i, v := range input_slice { - selected, err := selector(i, v) - if err != nil { + if selected, err := selector(i, v); err != nil { return nil, err - } + } else { - if selected { + if selected { - result[result_len] = v - result_len++ + r = append(r, v) + } } } - return result[0:result_len], nil + return r, nil } +// Selects elements of an input slice of []string to an output slice of +// []string, according to the given selector function. func SelectSliceOfString(input_slice []string, selector func(index int, input_item string) (bool, error)) ([]string, error) { - input_len := len(input_slice) - result := make([]string, input_len) - result_len := 0 + r := make([]string, 0, len(input_slice)) - for i, v := range input_slice { + for i, s := range input_slice { - selected, err := selector(i, v) - if err != nil { + if selected, err := selector(i, s); err != nil { return nil, err - } + } else { - if selected { + if selected { - result[result_len] = v - result_len++ + r = append(r, s) + } } } - return result[0:result_len], nil + return r, nil } /* ///////////////////////////// end of file //////////////////////////// */ diff --git a/slices/select_test.go b/slices/select_test.go index 4b684c7..2335437 100644 --- a/slices/select_test.go +++ b/slices/select_test.go @@ -8,6 +8,40 @@ import ( "testing" ) +func Benchmark_SelectSliceOfInt(b *testing.B) { + + inputs := [][]int{ + {}, + {1}, + {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + } + + for b.Loop() { + for _, input := range inputs { + slices.SelectSliceOfInt(input, func(_, _ int) (bool, error) { + return true, nil + }) + } + } +} + +func Benchmark_SelectSliceOfString(b *testing.B) { + + inputs := [][]string{ + {}, + {"1"}, + {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, + } + + for b.Loop() { + for _, input := range inputs { + slices.SelectSliceOfString(input, func(_ int, _ string) (bool, error) { + return true, nil + }) + } + } +} + func Test_SelectSliceOfInt(t *testing.T) { { @@ -208,69 +242,135 @@ func Test_SelectSliceOfInteger(t *testing.T) { } } - // int + // uint64 { { - input := []int{} + input := []uint64{} { r, _ := slices.SelectSliceOfInteger( input, - func(_, _ int) (bool, error) { return true, nil }, + func(_ int, _ uint64) (bool, error) { return true, nil }, ) - assert.Equal(t, []int{}, r) + assert.Equal(t, []uint64{}, r) } { r, _ := slices.SelectSliceOfInteger( input, - func(_, _ int) (bool, error) { return false, nil }, + func(_ int, _ uint64) (bool, error) { return false, nil }, ) - assert.Equal(t, []int{}, r) + assert.Equal(t, []uint64{}, r) } } { - input := []int{1} + input := []uint64{1} { r, _ := slices.SelectSliceOfInteger( input, - func(_, _ int) (bool, error) { return true, nil }, + func(_ int, _ uint64) (bool, error) { return true, nil }, ) - assert.Equal(t, []int{1}, r) + assert.Equal(t, []uint64{1}, r) } { r, _ := slices.SelectSliceOfInteger( input, - func(_, _ int) (bool, error) { return false, nil }, + func(_ int, _ uint64) (bool, error) { return false, nil }, ) - assert.Equal(t, []int{}, r) + assert.Equal(t, []uint64{}, r) } } { - input := []int{1, 2, 3, 4, 5, 6} + input := []uint64{1, 2, 3, 4, 5, 6} { r, _ := slices.SelectSliceOfInteger( input, - func(_, input_item int) (bool, error) { return 0 != (input_item % 2), nil }, + func(_ int, input_item uint64) (bool, error) { return 0 != (input_item % 2), nil }, ) - assert.Equal(t, []int{1, 3, 5}, r) + assert.Equal(t, []uint64{1, 3, 5}, r) } { r, _ := slices.SelectSliceOfInteger( input, - func(_, input_item int) (bool, error) { return 0 == (input_item % 2), nil }, + func(_ int, input_item uint64) (bool, error) { return 0 == (input_item % 2), nil }, ) - assert.Equal(t, []int{2, 4, 6}, r) + assert.Equal(t, []uint64{2, 4, 6}, r) } } } } + +func Test_SelectSliceOfString(t *testing.T) { + + { + input := []string{} + + { + r, _ := slices.SelectSliceOfString( + input, + func(_ int, _ string) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []string{}, r) + } + { + r, _ := slices.SelectSliceOfString( + input, + func(_ int, _ string) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []string{}, r) + } + } + + { + input := []string{"a"} + + { + r, _ := slices.SelectSliceOfString( + input, + func(_ int, _ string) (bool, error) { return true, nil }, + ) + + assert.Equal(t, []string{"a"}, r) + } + { + r, _ := slices.SelectSliceOfString( + input, + func(_ int, _ string) (bool, error) { return false, nil }, + ) + + assert.Equal(t, []string{}, r) + } + } + + { + input := []string{"", "a", "bcd", "d", "efghij", "kl"} + + { + r, _ := slices.SelectSliceOfString( + input, + func(_ int, input_item string) (bool, error) { return len(input_item) < 2, nil }, + ) + + assert.Equal(t, []string{"", "a", "d"}, r) + } + { + r, _ := slices.SelectSliceOfString( + input, + func(_ int, input_item string) (bool, error) { return len(input_item) >= 2, nil }, + ) + + assert.Equal(t, []string{"bcd", "efghij", "kl"}, r) + } + } +} From d0b3658957ad7170da64f4d23c398793e803f710 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:37:04 +1100 Subject: [PATCH 08/18] * refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; * refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; * changed signature of `EqualSlice()`, including making be a generic function (`EqualSlice[T]()`); --- CHANGES.md | 3 + TODO.md | 1 + slices/equal_slice.go | 124 ++++++++++++++++++++---------------------- slices/equal_test.go | 14 +++++ 4 files changed, 77 insertions(+), 65 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4c44645..016f6b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,9 @@ ## 0.10.0-alpha1 - 7th February 2026 +* refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; +* refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; +* changed signature of `EqualSlice()`, including making be a generic function (`EqualSlice[T]()`); * renamed `SelectSliceOfUinteger()` => `SelectSliceOfInteger()`; * simplified implementation of `SelectSliceOfInteger[T]()`; * added unit-tests for `SelectSliceOfInt()` and `SelectSliceOfString()`; diff --git a/TODO.md b/TODO.md index 6b0893f..d4055d2 100644 --- a/TODO.md +++ b/TODO.md @@ -29,6 +29,7 @@ recls for Go ## 0.11+ Items * simplify names, e.g. `CollectSlice()` => `Collect()`, and so forth; +* apply `~` on generics; * \ diff --git a/slices/equal_slice.go b/slices/equal_slice.go index 3d17010..37145e5 100644 --- a/slices/equal_slice.go +++ b/slices/equal_slice.go @@ -20,50 +20,18 @@ import ( // order. func EqualSliceOfInt(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 - } + return EqualSliceOfInteger(lhs, rhs) } // Indicates whether two []uint slices have the same size, contents, and // order. func EqualSliceOfUint(lhs, rhs []uint) 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 - } + return EqualSliceOfInteger(lhs, rhs) } +// Indicates whether two []N slices have the same size, contents, and +// order. func EqualSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](lhs, rhs []N) bool { len_l := len(lhs) @@ -134,58 +102,84 @@ func EqualSliceOfString(lhs, rhs []string) bool { } } -func EqualSlice(lhs, rhs any) bool { +func EqualSlice[T any](lhs, rhs []T) bool { // Check for typed variants - switch lhs_typed := lhs.(type) { + switch lhs_typed := any(lhs).(type) { + + case []int8: + + rhs_typed, _ := any(rhs).([]int8) + + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []int16: + + rhs_typed, _ := any(rhs).([]int16) + + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []int32: + + rhs_typed, _ := any(rhs).([]int32) + + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []int64: + rhs_typed, _ := any(rhs).([]int64) + + return EqualSliceOfInteger(lhs_typed, rhs_typed) case []int: - if rhs_typed, ok := rhs.([]int); ok { + rhs_typed, _ := any(rhs).([]int) - return EqualSliceOfInt(lhs_typed, rhs_typed) - } else { + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []uint8: - return false - } - case []float64: + rhs_typed, _ := any(rhs).([]uint8) - if rhs_typed, ok := rhs.([]float64); ok { + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []uint16: - return EqualSliceOfFloat64(lhs_typed, rhs_typed) - } else { + rhs_typed, _ := any(rhs).([]uint16) - return false - } - case []string: + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []uint32: - if rhs_typed, ok := rhs.([]string); ok { + rhs_typed, _ := any(rhs).([]uint32) - return EqualSliceOfString(lhs_typed, rhs_typed) - } else { + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []uint64: - return false - } - } + rhs_typed, _ := any(rhs).([]uint64) - // Generic comparison + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []uint: - lhs_t := reflect.TypeOf(lhs) - rhs_t := reflect.TypeOf(rhs) + rhs_typed, _ := any(rhs).([]uint) - // check both are slices + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []uintptr: - if reflect.Slice != lhs_t.Kind() { + rhs_typed, _ := any(rhs).([]uintptr) - return false - } + return EqualSliceOfInteger(lhs_typed, rhs_typed) + case []float64: - if reflect.Slice != rhs_t.Kind() { + rhs_typed, _ := any(rhs).([]float64) - return false + return EqualSliceOfFloat64(lhs_typed, rhs_typed) + case []string: + + rhs_typed, _ := any(rhs).([]string) + + return EqualSliceOfString(lhs_typed, rhs_typed) } + // Generic comparison + + lhs_t := reflect.TypeOf(lhs) + rhs_t := reflect.TypeOf(rhs) + // check element type lhs_k := lhs_t.Elem() diff --git a/slices/equal_test.go b/slices/equal_test.go index e599bfa..aff757d 100644 --- a/slices/equal_test.go +++ b/slices/equal_test.go @@ -8,6 +8,20 @@ import ( "testing" ) +func Test_EqualSlice(t *testing.T) { + + { + assert.True(t, slices.EqualSlice([]int{}, []int{})) + assert.True(t, slices.EqualSlice([]int{1}, []int{1})) + assert.False(t, slices.EqualSlice([]int{1}, []int{2})) + + assert.True(t, slices.EqualSlice([]int{1, 2, 3, 4}, []int{1, 2, 3, 4})) + assert.False(t, slices.EqualSlice([]int{1, 2, 3, 4}, []int{1, 2, 4, 3})) + + assert.True(t, slices.EqualSlice([]int{1, 2, 3, 4, 5}[:4], []int{1, 2, 3, 4, 6}[:4])) + } +} + func Test_EqualSliceOfInt(t *testing.T) { { From 732869e59cf85b8ac19b9a7784e9da7a57c56ae5 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:37:43 +1100 Subject: [PATCH 09/18] tidy --- strings/ascii.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/strings/ascii.go b/strings/ascii.go index d714561..8f55d38 100644 --- a/strings/ascii.go +++ b/strings/ascii.go @@ -4,7 +4,7 @@ /* * Created: 1st January 2026 - * Updated: 2nd January 2026 + * Updated: 7th February 2026 */ package strings @@ -18,11 +18,13 @@ package strings // by the standard `ToLower()` is desired. func ASCIIToLower(s string) string { b := []byte(s) + for i := 0; i < len(b); i++ { if b[i] >= 'A' && b[i] <= 'Z' { b[i] += 32 } } + return string(b) } @@ -35,11 +37,13 @@ func ASCIIToLower(s string) string { // by the standard `ToUpper()` is desired. func ASCIIToUpper(s string) string { b := []byte(s) + for i := 0; i < len(b); i++ { if b[i] >= 'a' && b[i] <= 'z' { b[i] -= 32 } } + return string(b) } From 4406e5dcc78e8ea4e9195518bec19b298368c85a Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:40:27 +1100 Subject: [PATCH 10/18] simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()` --- CHANGES.md | 1 + strings/ascii.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 016f6b9..da67ced 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## 0.10.0-alpha1 - 7th February 2026 +* simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()`; * refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; * refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; * changed signature of `EqualSlice()`, including making be a generic function (`EqualSlice[T]()`); diff --git a/strings/ascii.go b/strings/ascii.go index 8f55d38..7292fcd 100644 --- a/strings/ascii.go +++ b/strings/ascii.go @@ -17,10 +17,13 @@ package strings // are known to contain only ASCII and a faster conversion than is provided // by the standard `ToLower()` is desired. func ASCIIToLower(s string) string { + b := []byte(s) - for i := 0; i < len(b); i++ { - if b[i] >= 'A' && b[i] <= 'Z' { + for i, c := range b { + + if c >= 'A' && c <= 'Z' { + b[i] += 32 } } @@ -36,10 +39,13 @@ func ASCIIToLower(s string) string { // are known to contain only ASCII and a faster conversion than is provided // by the standard `ToUpper()` is desired. func ASCIIToUpper(s string) string { + b := []byte(s) - for i := 0; i < len(b); i++ { - if b[i] >= 'a' && b[i] <= 'z' { + for i, c := range b { + + if c >= 'a' && c <= 'z' { + b[i] -= 32 } } From 26bc6b6640651cdf015c1d1acf2c130394e4ca41 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:41:46 +1100 Subject: [PATCH 11/18] boilerplate --- TODO.md | 8 ++++---- slices/equal_slice.go | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index d4055d2..2b02320 100644 --- a/TODO.md +++ b/TODO.md @@ -19,11 +19,11 @@ recls for Go ## 0.10+ Items * change semantics of `CollectSlice()`, `EqualSlice()` to not take `any`, but (at least) `[]any`; -* correct all `slices` functions to proper naming, including `Uint` rather than `Uint`; -* `GenerateSliceOfInteger[T]()`; +* ~~correct all `slices` functions to proper naming, including `Uint` rather than `Uint`~~ - ✅; +* ~~`GenerateSliceOfInteger[T]()`~~ - ✅; * `SelectSlice[T]()`; -* expand coverage of specific types for `EqualSlice[T]()`; -* enhance code coverage in unit-tests; +* ~~expand coverage of specific types for `EqualSlice[T]()`~~ - ✅; +* ~~enhance code coverage in unit-tests~~ - ✅; ## 0.11+ Items diff --git a/slices/equal_slice.go b/slices/equal_slice.go index 37145e5..61be7b8 100644 --- a/slices/equal_slice.go +++ b/slices/equal_slice.go @@ -102,6 +102,7 @@ func EqualSliceOfString(lhs, rhs []string) bool { } } +// Indicates whether two []T slices have the same size, contents, and order. func EqualSlice[T any](lhs, rhs []T) bool { // Check for typed variants From 53b49e7f630a4f123eab443f6867637534844555 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:51:45 +1100 Subject: [PATCH 12/18] refactor `CollectSliceOfInt()` in terms of `CollectSliceOfInteger[T]()` --- CHANGES.md | 1 + slices/collect_slice.go | 13 ++----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index da67ced..076df16 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## 0.10.0-alpha1 - 7th February 2026 * simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()`; +* refactor `CollectSliceOfInt()` in terms of `CollectSliceOfInteger[T]()`; * refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; * refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; * changed signature of `EqualSlice()`, including making be a generic function (`EqualSlice[T]()`); diff --git a/slices/collect_slice.go b/slices/collect_slice.go index 1d824ad..4c5f2c7 100644 --- a/slices/collect_slice.go +++ b/slices/collect_slice.go @@ -53,18 +53,9 @@ func CollectSlice(input_slice any, fn func(input_item any) (any, error)) ([]any, } // This function maps an input slice of []int to an output slice of []int. -func CollectSliceOfInt(input_slice []int, fn func(input_item int) int) (result_slice []int) { +func CollectSliceOfInt(input_slice []int, collector func(input_item int) int) ([]int) { - result_slice = make([]int, len(input_slice)) - - for i, v := range input_slice { - - result := fn(v) - - result_slice[i] = result - } - - return + return CollectSliceOfInteger(input_slice, collector) } // This function maps an input slice of []N to an output slice of []N, where From 90efe9fd35ad7e7f9e78139a4c1b6ff9b1a3fcb9 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:52:29 +1100 Subject: [PATCH 13/18] standardisation --- README.md | 10 +++++----- slices/collect_slice.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a620c84..1415175 100644 --- a/README.md +++ b/README.md @@ -101,22 +101,22 @@ Modelled after **Ruby**'s `Enumerable#collect()`, these functions provide for tr func CollectSlice(input_slice any, fn func(input_item any) (any, error)) ([]any, error) // This function maps an input slice of []int to an output slice of []int. -func CollectSliceOfInt(input_slice []int, fn func(input_item int) int) (result_slice []int) +func CollectSliceOfInt(input_slice []int, collector func(input_item int) int) (result_slice []int) // This function maps an input slice of []N to an output slice of []N, where // N is any integer type. -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 CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, collector func(input_item N) N) (result_slice []N) // This function maps an input slice of []float64 to an output slice of // []float64. -func CollectSliceOfFloat64(input_slice []float64, fn func(input_item float64) float64) (result_slice []float64) +func CollectSliceOfFloat64(input_slice []float64, collector func(input_item float64) float64) (result_slice []float64) // This function maps an input slice of []string to an output slice of // []string. -func CollectSliceOfString(input_slice []string, fn func(input_item string) string) (result_slice []string) +func CollectSliceOfString(input_slice []string, collector func(input_item string) string) (result_slice []string) // This function maps an input slice of []T to an output slice of []string. -func CollectSliceIntoStringSlice[T any](input_slice []T, fn func(input_item *T) (string, error)) ([]string, error) +func CollectSliceIntoStringSlice[T any](input_slice []T, collector func(input_item *T) (string, error)) ([]string, error) ``` #### `EqualSlice` Functions diff --git a/slices/collect_slice.go b/slices/collect_slice.go index 4c5f2c7..bc5e268 100644 --- a/slices/collect_slice.go +++ b/slices/collect_slice.go @@ -60,13 +60,13 @@ func CollectSliceOfInt(input_slice []int, collector func(input_item int) int) ([ // This function maps an input slice of []N to an output slice of []N, where // N is any integer type. -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 CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 | uint32 | uint64 | uint | uintptr](input_slice []N, collector 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 := collector(v) result_slice[i] = result } @@ -76,13 +76,13 @@ func CollectSliceOfInteger[N int8 | int16 | int32 | int64 | int | uint8 | uint16 // This function maps an input slice of []float64 to an output slice of // []float64. -func CollectSliceOfFloat64(input_slice []float64, fn func(input_item float64) float64) (result_slice []float64) { +func CollectSliceOfFloat64(input_slice []float64, collector func(input_item float64) float64) (result_slice []float64) { result_slice = make([]float64, len(input_slice)) for i, v := range input_slice { - result := fn(v) + result := collector(v) result_slice[i] = result } @@ -92,26 +92,26 @@ func CollectSliceOfFloat64(input_slice []float64, fn func(input_item float64) fl // This function maps an input slice of []string to an output slice of // []string. -func CollectSliceOfString(input_slice []string, fn func(input_item string) string) (result_slice []string) { +func CollectSliceOfString(input_slice []string, collector func(input_item string) string) (result_slice []string) { result_slice = make([]string, len(input_slice)) for i, s := range input_slice { - result_slice[i] = fn(s) + result_slice[i] = collector(s) } return } // This function maps an input slice of []T to an output slice of []string. -func CollectSliceIntoStringSlice[T any](input_slice []T, fn func(input_item *T) (string, error)) ([]string, error) { +func CollectSliceIntoStringSlice[T any](input_slice []T, collector func(input_item *T) (string, error)) ([]string, error) { result_slice := make([]string, len(input_slice)) for i, t := range input_slice { - s, err := fn(&t) + s, err := collector(&t) if err != nil { return []string{}, err } From c3b18aa3e10cb5e7335614b1d039e2de35dfea73 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 17:55:19 +1100 Subject: [PATCH 14/18] changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T]()`) --- CHANGES.md | 1 + README.md | 5 ++--- slices/collect_slice.go | 38 ++++++++------------------------------ slices/collect_test.go | 29 ++++++++--------------------- 4 files changed, 19 insertions(+), 54 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 076df16..d4b09b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ ## 0.10.0-alpha1 - 7th February 2026 * simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()`; +* changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T]()`); * refactor `CollectSliceOfInt()` in terms of `CollectSliceOfInteger[T]()`; * refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; * refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; diff --git a/README.md b/README.md index 1415175..50bdfbb 100644 --- a/README.md +++ b/README.md @@ -96,9 +96,8 @@ Modelled after **Ruby**'s `Enumerable#collect()`, these functions provide for tr ```Go // in "github.com/synesissoftware/ANGoLS/slices" -// This function maps an input slice of arbitrary type to an output slice of -// type []any. -func CollectSlice(input_slice any, fn func(input_item any) (any, error)) ([]any, error) +// This function maps an input slice of T[] to an output slice of []T. +func CollectSlice[T any](input_slice []T, collector func(index int, input_item *T) (T, error)) ([]T, error) // This function maps an input slice of []int to an output slice of []int. func CollectSliceOfInt(input_slice []int, collector func(input_item int) int) (result_slice []int) diff --git a/slices/collect_slice.go b/slices/collect_slice.go index bc5e268..6c357b3 100644 --- a/slices/collect_slice.go +++ b/slices/collect_slice.go @@ -9,44 +9,22 @@ package slices -import ( - "fmt" - "reflect" -) - // ///////////////////////////////////////////////////////////////////////// // Collect* -// This function maps an input slice of arbitrary type to an output slice of -// type []any. -func CollectSlice(input_slice any, fn func(input_item any) (any, error)) ([]any, error) { - - sl_t := reflect.TypeOf(input_slice) - - if reflect.Slice != sl_t.Kind() { +// This function maps an input slice of T[] to an output slice of []T. +func CollectSlice[T any](input_slice []T, collector func(index int, input_item *T) (T, error)) ([]T, error) { - msg := fmt.Sprintf("CollectSlice() called with input_slice of type %T; slice required", input_slice) - - panic(msg) - } + result := make([]T, len(input_slice)) - sl_v := reflect.ValueOf(input_slice) - len := sl_v.Len() + for i := 0; i != len(input_slice); i++ { - result := make([]any, len) + if r, err := collector(i, &input_slice[i]); err != nil { + return nil, err + } else { - for i := 0; len != i; i++ { - - p := sl_v.Index(i) - v := p.Interface() - - r, e := fn(v) - if e != nil { - - return nil, e + result[i] = r } - - result[i] = r } return result, nil diff --git a/slices/collect_test.go b/slices/collect_test.go index 351e8cb..847460d 100644 --- a/slices/collect_test.go +++ b/slices/collect_test.go @@ -3,6 +3,8 @@ package slices_test import ( "github.com/synesissoftware/ANGoLS/slices" + "github.com/stretchr/testify/assert" + "fmt" "strconv" "strings" @@ -17,40 +19,25 @@ const ( func Test_Collect_Array_1_ints_to_ints(t *testing.T) { - fn := func(input any) (any, error) { - - if i, ok := input.(int); ok { + collector := func(index int, input_item *int) (int, error) { - if i < 0 { + if *input_item < 0 { - return -i, nil - } + return -*input_item, nil } - return input, nil + return *input_item, nil } ints := []int{1, 2, 3} - r, err := slices.CollectSlice(ints, fn) + r, err := slices.CollectSlice(ints, collector) if err != nil { t.Errorf("Collect() failed: %v", err) } else { - for ix, v := range r { - - if i, ok := v.(int); !ok { - - t.Errorf("Element (%T)%v of non-int type at index %d\n", v, v, ix) - } else { - - if ints[ix] != i { - - t.Errorf("Element (%T)%v at index %d is different from expected value %d\n", v, v, ix, ints[ix]) - } - } - } + assert.Equal(t, ints, r) } } From ab4cbf234643b40ce6c6d66670fbef906f6c4341 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 18:05:41 +1100 Subject: [PATCH 15/18] changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T, U]()`) --- CHANGES.md | 2 +- slices/collect_slice.go | 7 ++++--- slices/collect_test.go | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index d4b09b9..4094fdd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,7 +3,7 @@ ## 0.10.0-alpha1 - 7th February 2026 * simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()`; -* changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T]()`); +* changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T, U]()`); * refactor `CollectSliceOfInt()` in terms of `CollectSliceOfInteger[T]()`; * refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; * refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; diff --git a/slices/collect_slice.go b/slices/collect_slice.go index 6c357b3..24b0995 100644 --- a/slices/collect_slice.go +++ b/slices/collect_slice.go @@ -12,10 +12,11 @@ package slices // ///////////////////////////////////////////////////////////////////////// // Collect* -// This function maps an input slice of T[] to an output slice of []T. -func CollectSlice[T any](input_slice []T, collector func(index int, input_item *T) (T, error)) ([]T, error) { +// This function maps an input slice of T[] to an output slice of []U using +// the given collector. +func CollectSlice[T any, U any](input_slice []T, collector func(index int, input_item *T) (U, error)) ([]U, error) { - result := make([]T, len(input_slice)) + result := make([]U, len(input_slice)) for i := 0; i != len(input_slice); i++ { diff --git a/slices/collect_test.go b/slices/collect_test.go index 847460d..d7a9667 100644 --- a/slices/collect_test.go +++ b/slices/collect_test.go @@ -17,6 +17,24 @@ const ( // Tests +func Test_CollectSlice_int_INTO_string(t *testing.T) { + + collector := func(index int, input_item *int) (string, error) { + + return strconv.Itoa(*input_item), nil + } + + input := []int{1, -2, 3} + expected := []string{"1", "-2", "3"} + + actual, err := slices.CollectSlice(input, collector) + if err != nil { + + } else { + assert.Equal(t, expected, actual) + } +} + func Test_Collect_Array_1_ints_to_ints(t *testing.T) { collector := func(index int, input_item *int) (int, error) { From a0b7cf67ebc4e95cae126ecd4225de2bed8f93e7 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 18:10:01 +1100 Subject: [PATCH 16/18] refactored `CollectSliceIntoStringSlice()` in terms of `CollectSlice[T, U]()` --- CHANGES.md | 1 + slices/collect_slice.go | 16 +++------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4094fdd..71caca5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ * simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()`; * changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T, U]()`); +* refactored `CollectSliceIntoStringSlice()` in terms of `CollectSlice[T, U]()`; * refactor `CollectSliceOfInt()` in terms of `CollectSliceOfInteger[T]()`; * refactored `EqualSliceOfInt()` in terms of `EqualSliceOfInteger[T]()`; * refactored `EqualSliceOfUint()` in terms of `EqualSliceOfInteger[T]()`; diff --git a/slices/collect_slice.go b/slices/collect_slice.go index 24b0995..240c294 100644 --- a/slices/collect_slice.go +++ b/slices/collect_slice.go @@ -86,19 +86,9 @@ func CollectSliceOfString(input_slice []string, collector func(input_item string // This function maps an input slice of []T to an output slice of []string. func CollectSliceIntoStringSlice[T any](input_slice []T, collector func(input_item *T) (string, error)) ([]string, error) { - result_slice := make([]string, len(input_slice)) - - for i, t := range input_slice { - - s, err := collector(&t) - if err != nil { - return []string{}, err - } - - result_slice[i] = s - } - - return result_slice, nil + return CollectSlice(input_slice, func(_ int, input_item *T) (string, error) { + return collector(input_item) + }) } /* ///////////////////////////// end of file //////////////////////////// */ From bebe440cc0f489dd239e265257f973dd800d31a0 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 18:10:31 +1100 Subject: [PATCH 17/18] boilerplate --- TODO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 2b02320..bb766da 100644 --- a/TODO.md +++ b/TODO.md @@ -18,7 +18,7 @@ recls for Go ## 0.10+ Items -* change semantics of `CollectSlice()`, `EqualSlice()` to not take `any`, but (at least) `[]any`; +* ~~change semantics of `CollectSlice()`, `EqualSlice()` to not take `any`, but (at least) `[]any`~~ - ✅; * ~~correct all `slices` functions to proper naming, including `Uint` rather than `Uint`~~ - ✅; * ~~`GenerateSliceOfInteger[T]()`~~ - ✅; * `SelectSlice[T]()`; From ebf5c3f3f51b5dd0e24073b374b9071dd9bf85d7 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 7 Feb 2026 18:12:31 +1100 Subject: [PATCH 18/18] version --- CHANGES.md | 2 +- version.go | 2 +- version_test.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 71caca5..63593c4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # **ANGoLS** Changes -## 0.10.0-alpha1 - 7th February 2026 +## 0.10.0-beta1 - 7th February 2026 * simple refactoring of `ASCIIToLower()` and `ASCIIToUpper()`; * changed signature of `CollectSlice()`, including making be a generic function (`CollectSlice[T, U]()`); diff --git a/version.go b/version.go index 9039645..ab275ac 100644 --- a/version.go +++ b/version.go @@ -15,7 +15,7 @@ const ( VersionMajor uint16 = 0 VersionMinor uint16 = 10 VersionPatch uint16 = 0 - VersionAB uint16 = 0x4001 + VersionAB uint16 = 0x8001 Version uint64 = (uint64(VersionMajor) << 48) + (uint64(VersionMinor) << 32) + (uint64(VersionPatch) << 16) + (uint64(VersionAB) << 0) ) diff --git a/version_test.go b/version_test.go index 4cd2fd9..870d713 100644 --- a/version_test.go +++ b/version_test.go @@ -12,7 +12,7 @@ const ( Expected_VersionMajor uint16 = 0 Expected_VersionMinor uint16 = 10 Expected_VersionPatch uint16 = 0 - Expected_VersionAB uint16 = 0x4001 + Expected_VersionAB uint16 = 0x8001 ) func Test_Version_Elements(t *testing.T) { @@ -23,9 +23,9 @@ func Test_Version_Elements(t *testing.T) { } func Test_Version(t *testing.T) { - require.Equal(t, uint64(0x0000_000A_0000_4001), angols.Version) + require.Equal(t, uint64(0x0000_000A_0000_8001), angols.Version) } func Test_Version_String(t *testing.T) { - require.Equal(t, "0.10.0-alpha1", angols.VersionString()) + require.Equal(t, "0.10.0-beta1", angols.VersionString()) }