Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# **ANGoLS** Changes

## 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]()`);
* 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]()`;
* 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()`;
* refactored `SelectSliceOfInt()` in terms of `SelectSliceOfInteger[T]()`;
* refactored `SelectSliceOfUint()` in terms of `SelectSliceOfInteger[T]()`;
* simplified implementation of `SelectSliceOfString()`;


## 0.9.1 - 7th February 2026

* fixed `EqualSliceOfInteger[]()` return type;
Expand Down
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,26 @@ 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, 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
Expand All @@ -132,7 +131,7 @@ func EqualSliceOfInt(lhs, rhs []int) bool

// Indicates whether two []uint slices have the same size, contents, and
// order.
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

Expand Down Expand Up @@ -160,7 +159,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)

// Creates a slice of a given size and populates its values with the given
// generator (which may be nil).
Expand All @@ -177,9 +176,9 @@ Modelled after **Ruby**'s `Enumerable#select()`, these functions provide for sel

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 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)
```
Expand Down
16 changes: 9 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ 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

* 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]()`;
* ~~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]()`;
* expand coverage of specific types for `EqualSlice[T]()`;
* ~~expand coverage of specific types for `EqualSlice[T]()`~~ - ✅;
* ~~enhance code coverage in unit-tests~~ - ✅;


## 0.11+ Items

* simplify names, e.g. `CollectSlice()` => `Collect()`, and so forth;
* apply `~` on generics;
* \<none>


12 changes: 6 additions & 6 deletions select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
82 changes: 21 additions & 61 deletions slices/collect_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,73 +9,43 @@

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() {

msg := fmt.Sprintf("CollectSlice() called with input_slice of type %T; slice required", input_slice)

panic(msg)
}

sl_v := reflect.ValueOf(input_slice)
len := sl_v.Len()

result := make([]any, len)
// 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) {

for i := 0; len != i; i++ {
result := make([]U, len(input_slice))

p := sl_v.Index(i)
v := p.Interface()
for i := 0; i != len(input_slice); i++ {

r, e := fn(v)
if e != nil {
if r, err := collector(i, &input_slice[i]); err != nil {
return nil, err
} else {

return nil, e
result[i] = r
}

result[i] = r
}

return result, nil
}

// 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) {

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

for i, v := range input_slice {
func CollectSliceOfInt(input_slice []int, collector func(input_item int) int) ([]int) {

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
// 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
}
Expand All @@ -85,13 +55,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
}
Expand All @@ -101,34 +71,24 @@ 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) {

result_slice := make([]string, len(input_slice))

for i, t := range input_slice {

s, err := fn(&t)
if err != nil {
return []string{}, err
}

result_slice[i] = s
}
func CollectSliceIntoStringSlice[T any](input_slice []T, collector func(input_item *T) (string, error)) ([]string, error) {

return result_slice, nil
return CollectSlice(input_slice, func(_ int, input_item *T) (string, error) {
return collector(input_item)
})
}

/* ///////////////////////////// end of file //////////////////////////// */
Loading
Loading