|
@@ -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 {
|