1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-11-25 22:21:49 +02:00

fix: add inline annotations

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2025-11-06 10:54:24 +01:00
parent 56c8f1b034
commit 0d3a8634b1
22 changed files with 681 additions and 13 deletions

View File

@@ -17,10 +17,52 @@ package array
func Slice[GA ~[]A, A any](low, high int) func(as GA) GA {
return func(as GA) GA {
length := len(as)
// Handle negative indices - count backward from the end
if low < 0 {
low = max(length+low, 0)
}
if high < 0 {
high = max(length+high, 0)
}
if low > length {
return Empty[GA, A]()
}
// End index > array length: slice to the end
if high > length {
high = length
}
// Start >= end: return empty array
if low >= high {
return Empty[GA, A]()
}
return as[low:high]
}
}
func SliceRight[GA ~[]A, A any](start int) func(as GA) GA {
return func(as GA) GA {
length := len(as)
// Handle negative indices - count backward from the end
if start < 0 {
start = max(length+start, 0)
}
// Start index > array length: return empty array
if start > length {
return Empty[GA, A]()
}
return as[start:]
}
}
func IsEmpty[GA ~[]A, A any](as GA) bool {
return len(as) == 0
}