mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 11:22:22 -07:00
Merge pull request #1389 from ap29600/slice_scanner
Add slice/scanner proc
This commit is contained in:
@@ -304,6 +304,23 @@ filter :: proc(s: $S/[]$U, f: proc(U) -> bool, allocator := context.allocator) -
|
||||
return r[:]
|
||||
}
|
||||
|
||||
scanner :: proc (s: $S/[]$U, initializer: $V, f: proc(V, U)->V, allocator := context.allocator) -> []V {
|
||||
if len(s) == 0 { return {} }
|
||||
|
||||
res := make([]V, len(s), allocator)
|
||||
p := as_ptr(s)
|
||||
q := as_ptr(res)
|
||||
r := initializer
|
||||
|
||||
for l := len(s); l > 0; l -= 1 {
|
||||
r = f(r, p[0])
|
||||
q[0] = r
|
||||
p = p[1:]
|
||||
q = q[1:]
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
min :: proc(s: $S/[]$T) -> (res: T, ok: bool) where intrinsics.type_is_ordered(T) #optional_ok {
|
||||
|
||||
Reference in New Issue
Block a user