renamed iter.as_iterator to iter.as_iter
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 7 Jan 2023 00:02:33 +0000 (18:02 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 7 Jan 2023 00:02:33 +0000 (18:02 -0600)
19 files changed:
core/container/bucket_array.onyx
core/container/iter.onyx
core/container/list.onyx
core/container/map.onyx
core/container/set.onyx
core/misc/arg_parse.onyx
core/net/tcp.onyx
examples/20_auto_return.onyx
examples/21_quick_functions.onyx
tests/aoc-2021/day03.onyx
tests/aoc-2021/day07.onyx
tests/aoc-2021/day09.onyx
tests/aoc-2021/day11.onyx
tests/aoc-2021/day12.onyx
tests/auto_poly.onyx
tests/bucket_array.onyx
tests/interfaces.onyx
tests/lazy_iterators.onyx
tests/remove_test.onyx

index 52918f54646c6223e65e8d7eec8e06f64a00716d..0cfb8d5eac0e1da8bd659799e0ad6787ecf33cbd 100644 (file)
@@ -101,8 +101,8 @@ for_each :: macro (b: Bucket_Array($T), body: Code) {
     }
 }
 
-#match iter.as_iterator iterator
-iterator :: (b: ^Bucket_Array($T)) -> Iterator(T) {
+#match iter.as_iter as_iter
+as_iter :: (b: ^Bucket_Array($T)) -> Iterator(T) {
     Context :: struct (T: type_expr) {
         ba         : ^Bucket_Array(T);
         bucket_idx : i32;
index fba14a0af2aeec9336f3cf9be55b33a7f8db1b0c..ed58561d251c557a433b04a7f7c7f666b00525a2 100644 (file)
@@ -2,10 +2,10 @@ package core.iter
 
 use core {memory, alloc, array, Pair}
 
-as_iterator :: #match {}
+as_iter :: #match {}
 
 Iterable :: interface (t: $T) {
-    { as_iterator(t) } -> Iterator;
+    { as_iter(t) } -> Iterator;
 }
 
 close :: (it: Iterator($T)) {
@@ -31,11 +31,36 @@ ImplicitIterator :: interface (t: $T) {
 }
 
 #overload #precedence 10000
-as_iterator :: (x: ^$T/ImplicitIterator) => {
+as_iter :: (x: ^$T/ImplicitIterator) => {
     x->iter_open();
     return generator_no_copy(x, T.iter_next, T.iter_close);
 }
 
+// nocheckin
+// Does it make sense for the language to have
+// the iterator "methods" as actual methods
+// on every iterator type? Or should you
+// just have to use the `iter.` variants
+// instead?
+#inject Iterator {
+    filter :: filter;
+    map :: map;
+    zip :: zip;
+
+    take_one :: take_one;
+    take :: take;
+    take_while :: take_while;
+    skip :: skip;
+    skip_while :: skip_while;
+    
+    enumerate :: enumerate;
+
+    fold :: fold;
+    count :: count;
+    some :: some;
+    every :: every;
+}
+
 
 // Iterator Modifiers
 
@@ -503,9 +528,9 @@ enumerate :: #match #local {}
 
 #overload
 enumerate :: macro (it: $T/Iterable, start_index: i32 = 0) => {
-    as_iterator :: as_iterator
+    as_iter :: as_iter
     enumerate :: enumerate
-    return enumerate(as_iterator(it), start_index);
+    return enumerate(as_iter(it), start_index);
 }
 
 #overload
@@ -583,10 +608,10 @@ from_array :: (arr: [] $T) => generator(
 
 
 #overload
-as_iterator :: from_array
+as_iter :: from_array
 
 #overload
-as_iterator :: (x: ^[..] $T) -> Iterator(T) {
+as_iter :: (x: ^[..] $T) -> Iterator(T) {
     Context :: struct (T: type_expr) {
         arr: ^[..] T;
         current: u32;
@@ -622,7 +647,7 @@ as_iterator :: (x: ^[..] $T) -> Iterator(T) {
 }
 
 #overload
-as_iterator :: (x: ^[..] $T, by_pointer: bool) -> Iterator(^T) {
+as_iter :: (x: ^[..] $T, by_pointer: bool) -> Iterator(^T) {
     Context :: struct (T: type_expr) {
         arr: ^[..] T;
         current: u32;
@@ -658,7 +683,7 @@ as_iterator :: (x: ^[..] $T, by_pointer: bool) -> Iterator(^T) {
 }
 
 #overload
-as_iterator :: (r: range) -> Iterator(i32) {
+as_iter :: (r: range) -> Iterator(i32) {
     Context :: struct {
         r: range;
         v: i32;
@@ -699,7 +724,7 @@ fold :: #match #local {}
 #overload
 fold :: macro (it: $T/Iterable, init: $R, combine: $S) => {
     fold :: fold
-    return fold(as_iterator(it), init, combine);
+    return fold(as_iter(it), init, combine);
 }
 
 #overload
@@ -716,7 +741,7 @@ count :: #match #local {}
 #overload
 count :: macro (it: $T/Iterable, cond: $F) => {
     count :: count
-    return count(as_iterator(it), cond);
+    return count(as_iter(it), cond);
 }
 
 #overload
@@ -731,8 +756,8 @@ some :: #match #local {}
 #overload
 some :: macro (it: $T/Iterable, cond: $F) => {
     some :: some
-    as_iterator :: as_iterator
-    return some(as_iterator(it), cond);
+    as_iter :: as_iter
+    return some(as_iter(it), cond);
 }
 
 #overload
@@ -746,8 +771,8 @@ every :: #match #local {}
 #overload
 every :: macro (it: $T/Iterable, cond: $F) => {
     every :: every
-    as_iterator :: as_iterator
-    return every(as_iterator(it), cond);
+    as_iter :: as_iter
+    return every(as_iter(it), cond);
 }
 
 #overload
@@ -757,13 +782,13 @@ every :: (it: Iterator($T), cond: (T) -> bool) -> bool {
 }
 
 prod :: (x: $I1/Iterable, y: $I2/Iterable) => {
-    y_iter   := as_iterator(y);
+    y_iter   := as_iter(y);
     y_val, _ := take_one(y_iter);
 
     return generator(
         ^.{
             x = x,
-            x_iter = as_iterator(x),
+            x_iter = as_iter(x),
 
             y_iter = y_iter,
             y_val  = y_val
@@ -778,7 +803,7 @@ prod :: (x: $I1/Iterable, y: $I2/Iterable) => {
             ctx.y_val, cont = take_one(ctx.y_iter);
             if !cont do return .{}, false;
 
-            ctx.x_iter = as_iterator(ctx.x);
+            ctx.x_iter = as_iter(ctx.x);
             x_val, cont = take_one(ctx.x_iter);
             if !cont do return .{}, false;
 
@@ -828,9 +853,9 @@ comp :: macro (i: Iterator($V), value: Code) => {
 
 #overload
 comp :: macro (i: $I/Iterable, value: Code) => {
-    as_iterator :: as_iterator
+    as_iter :: as_iter
     comp        :: comp
-    return comp(as_iterator(i), value);
+    return comp(as_iter(i), value);
 }
 
 
@@ -882,8 +907,8 @@ generator_no_copy :: (ctx: ^$Ctx, gen: (^Ctx) -> ($T, bool), close: (^Ctx) -> vo
     #overload
     distributor :: macro (it: $T/Iterable) => {
         distributor :: distributor;
-        as_iterator :: as_iterator;
-        return distributor(as_iterator(it));
+        as_iter :: as_iter;
+        return distributor(as_iter(it));
     }
 
     #overload
@@ -928,16 +953,16 @@ generator_no_copy :: (ctx: ^$Ctx, gen: (^Ctx) -> ($T, bool), close: (^Ctx) -> vo
     #overload
     parallel_for :: macro (iterable: $I/Iterable, thread_count: u32, thread_data: ^$Ctx, body: Code) {
         parallel_for :: parallel_for;
-        as_iterator  :: as_iterator;
+        as_iter  :: as_iter;
 
-        parallel_for(as_iterator(iterable), thread_count, thread_data, body);
+        parallel_for(as_iter(iterable), thread_count, thread_data, body);
     }
 
     #overload
     parallel_for :: macro (iter: Iterator($T), thread_count: u32, thread_data: ^$Ctx, body: Code) {
         use core {thread, alloc}
         distributor :: distributor;
-        as_iterator :: as_iterator;
+        as_iter :: as_iter;
 
         if thread_count != 0 {
             dist := distributor(iter);
index 0838fda93ae0256af9439912e5dd7846d9c63bf1..aedfd41b66e67151f90de3292877d70838290958 100644 (file)
@@ -149,7 +149,7 @@ map :: #match #local {}
 }
 
 
-#match core.iter.as_iterator as_iter
+#match core.iter.as_iter as_iter
 as_iter :: (list: ^List) =>
     core.iter.generator(^.{current = list.first}, (ctx) => {
         if ctx.current != null {
index c5986139a57f20d3b445593a40c4b9227f8e8992..b17adb0a4810e0bc63fa78b59cd6fc1354356a63 100644 (file)
@@ -183,8 +183,7 @@ literal :: ($Key: type_expr, $Value: type_expr, values: [] MapLiteralValue(Key,
 }
 
 
-#overload core.iter.as_iterator as_iter
-
+#overload core.iter.as_iter as_iter
 as_iter :: (m: ^Map) =>
     core.iter.generator(
         ^.{ m = m, i = 0 },
index 066733febbba6c58377bb26be77cbf75d8d2ee58..1ac375b342f865803f2b92a51a5571d3c575b370 100644 (file)
@@ -118,8 +118,7 @@ empty :: (use set: ^Set) -> bool {
     return entries.count == 0;
 }
 
-#overload core.iter.as_iterator as_iter
-
+#overload core.iter.as_iter as_iter
 as_iter :: (s: ^Set) =>
     core.iter.generator(
         ^.{ s = s, i = 0 },
index 43dc396f00b20c14a166440b55c08906160085ec..623e857c542b1a2da0c01b4f352521af4ddac65e 100644 (file)
@@ -3,7 +3,7 @@ package core.arg_parse
 use core
 
 arg_parse :: (c_args: [] cstr, output: any) -> bool {
-    arg_iter := iter.as_iterator(c_args)
+    arg_iter := iter.as_iter(c_args)
              |> iter.map(string.from_cstr);
     defer arg_iter.close(arg_iter.data);
 
@@ -55,4 +55,4 @@ arg_parse :: (c_args: [] cstr, output: any) -> bool {
     }
 
     return true;
-}
\ No newline at end of file
+}
index 18864fb59006bd4a764b11a241f76a2a39f28b04..696501b92edfb60149a3a79f6819e5528d8e6f66 100644 (file)
@@ -321,7 +321,7 @@ tcp_server_broadcast :: (use server: ^TCP_Server, data: [] u8, except: ^TCP_Serv
 
 tcp_server_handle_events :: macro (server: ^TCP_Server, handler: Code) {
     while server->pulse() {
-        for iter.as_iterator(^server.connection) {
+        for iter.as_iter(^server.connection) {
             switch it.kind do #unquote handler;
         }
     }
index 5a52db096b6aaaa787594f2a4866ff2c17c1c3e1..041397008c59a804e824da5baf2fa46d10a84ea3 100644 (file)
@@ -34,7 +34,7 @@ main :: (args: [] cstr) {
             return arr;
         }
 
-        return consume_inner(iter.as_iterator(it));
+        return consume_inner(iter.as_iter(it));
     }
 
 
index 2a4535779812ca5cdb246fb04a1787918893041b..d43abc843a19f9380fa32f5c6989cedfb05fce32 100644 (file)
@@ -35,7 +35,7 @@ main :: (args) => {
     println(quickest_no_types(3, 4.0f));
 
     // This is an example of what the iter package looks like.
-    val := iter.as_iterator(range.{ 20, 1, -1 })
+    val := iter.as_iter(range.{ 20, 1, -1 })
             |> iter.map(x => x * 2)
             |> iter.map(x => cast(f32) x)
             |> iter.filter(x => x > 20)
index db94746eb9927cf3d2b3d618fa2c39d6c157f47d..243ea2390f78af4b38e38e76c56ed364fa5df6e6 100644 (file)
@@ -72,11 +72,11 @@ main :: (args) => {
             }
         }
 
-        for iter.as_iterator(range.{ BITS - 1, 0, -1 }) {
+        for iter.as_iter(range.{ BITS - 1, 0, -1 }) {
             filter_array(oxygen_array, it, #(A >= B));
             filter_array(co2_array,    it, #(A <  B));
         }
 
         printf("Part 2: {}\n", oxygen_array[0] * co2_array[0]);
     }
-}
\ No newline at end of file
+}
index f4fb8c081b8bdc0b127c4d5c771ddb07279e13d2..e96d3c57a4cac9c7e47bc5ce56d755841b1c253e 100644 (file)
@@ -7,7 +7,7 @@ main :: (args) => {
         reader := io.reader_make(file);
         nums := io.read_all(^reader)
             |> string.split(#char ",")
-            |> iter.as_iterator()
+            |> iter.as_iter()
             |> iter.map((x) => cast(i32) conv.parse_int(x))
             |> iter.to_array();
 
@@ -31,4 +31,4 @@ main :: (args) => {
 
         printf("Part 2: {} with fuel {}\n", best_middle, min_cost);
     }
-}
\ No newline at end of file
+}
index 2142a04230e76f4e545cd4997e6925f373855699..9adce7667e3641a2065ff05e3570827555441941 100644 (file)
@@ -120,11 +120,11 @@ main :: (args) => {
 
         array.quicksort(lowest_count.entries, (a, b) => b.value - a.value);
 
-        answer := iter.as_iterator(lowest_count.entries)
+        answer := iter.as_iter(lowest_count.entries)
                |> iter.map((x) => x.value)
                |> iter.take(3)
                |> iter.fold(1, (x, y) => x * y);
 
         printf("Part 2: {}\n", answer);
     }
-}
\ No newline at end of file
+}
index 74c417128401993b655b020437b0d80b82d8bf1b..c4346348a2e9ed677af553da14da97a3d9e8a448 100644 (file)
@@ -50,7 +50,7 @@ main :: (args) => {
                 }
             }
 
-            for flash: iter.as_iterator(^to_flash) {
+            for flash: iter.as_iter(^to_flash) {
                 for y: -1 .. 2 do for x: -1 .. 2 {
                     if y == 0 && x == 0 do continue;
 
@@ -60,7 +60,7 @@ main :: (args) => {
                 }
             }
 
-            for flash: iter.as_iterator(^to_flash) {
+            for flash: iter.as_iter(^to_flash) {
                 set_octopus(flash.x, flash.y, 0);
                 if step <= 100 do flash_count += 1;
             }
index 51d30757e73de96536ab7112b630709d4bdc3a8e..3d701d046f1120a3bbc21b6a3878e5e3b5852ecc 100644 (file)
@@ -45,11 +45,11 @@ main :: (args) => {
             *name_copy = name;
 
             return iter.concat(
-                iter.as_iterator(edges)
+                iter.as_iter(edges)
                 |> iter.filter(name_copy, (x, n) => x.a == *n)
                 |> iter.map(x => x.b),
 
-                iter.as_iterator(edges)
+                iter.as_iter(edges)
                 |> iter.filter(name_copy, (x, n) => x.b == *n)
                 |> iter.map(x => x.a)
             );
@@ -61,7 +61,7 @@ main :: (args) => {
         }
 
         edge_map: Map(str, [] str);
-        for v: iter.as_iterator(^verticies) {
+        for v: iter.as_iter(^verticies) {
             edge_map[*v] = children_of(^edges, *v) |> iter.to_array();
         }
 
index 84de9c4e7903c15acaa466aa6c0c623a926abefc..6c1a15cb665bfc1693d60df895d10f7573b0ba2d 100644 (file)
@@ -31,7 +31,7 @@ f :: (thing: ^Thing, other: typeof thing) {
 
 main :: (args) => {
     m: Map(i32, str);
-    dumb(iter.as_iterator(1 .. 10), ^m);
+    dumb(iter.as_iter(1 .. 10), ^m);
 
     V :: Vector2(i32)
     v1 := V.{ 1, 0 };
@@ -43,7 +43,7 @@ main :: (args) => {
     t: Thing(f32);
     f(^t, ^t);
 
-    for iter.as_iterator(0 .. 100) |> iter.map(x => x * 2) |> iter.filter(x => x <= 10) {
+    for iter.as_iter(0 .. 100) |> iter.map(x => x * 2) |> iter.filter(x => x <= 10) {
         println(it);
     }
 }
index c449fcbf069b0649c97230e7ad9e4632081d4ad9..550dbfa3af3f6f2d450efc950e2425eb3f191a9c 100644 (file)
@@ -14,9 +14,9 @@ main :: (args: [] cstr) {
         sum += *it;
     });
 
-    for it: bucket_array.iterator(^ba) {
+    for it: bucket_array.as_iter(^ba) {
         printf("{}\n", it);
     }
 
     printf("Sum is {}\n", sum);
-}
\ No newline at end of file
+}
index 6e51366ed008b25c9631cf978ab28e8536b3a5ec..8ba891ef2489bb479b43206c38e2b7f9f44262c7 100644 (file)
@@ -89,7 +89,7 @@ consume :: macro (x: $T/iter.Iterable) => {
         },
     }
 
-    iterator := iter.as_iterator(x);
+    iterator := iter.as_iter(x);
     return consume_inner(iterator);
 }
 
index ae30bd3e3272f3ff5bdaf4c03a4eb208e85279ea..42b630f9813e9a7c5675fb341ec9202ffef9f8e7 100644 (file)
@@ -40,7 +40,7 @@ main :: (args: [] cstr) {
         }
     }
 
-    iterator := iter.as_iterator(1 .. 11)
+    iterator := iter.as_iter(1 .. 11)
                 |> iter.map((x: i32) -> i32     { return x * 2; })
                 |> iter.filter((x: i32) -> bool { return x > 10; })
                 |> iter.map((x: i32) -> i32     { return x + 42; });
index 7b1077fc7ee45b1cd2e55f0ba89d9d3c390cfae1..ddddedb96dff37556991070d43774706a051b450 100644 (file)
@@ -8,11 +8,11 @@ main :: (args) => {
 
     println(x);
 
-    for iter.as_iterator(^x) {
+    for iter.as_iter(^x) {
         if it % 2 == 0 {
             #remove;
         }
     }
 
     println(x);
-}
\ No newline at end of file
+}