From 9cc314bbcf02a7fd5bab460a672025d222519228 Mon Sep 17 00:00:00 2001 From: Dorai Sitaram Date: Mon, 9 Sep 2024 14:53:10 -0400 Subject: [PATCH] Add annotation for table-from-raw-array(), checking arg is indeed a raw array of rows #1758 --- src/arr/trove/tables.arr | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/arr/trove/tables.arr b/src/arr/trove/tables.arr index f806079e2..79fda3788 100644 --- a/src/arr/trove/tables.arr +++ b/src/arr/trove/tables.arr @@ -1,5 +1,5 @@ provide: - * hiding (is-kv-pairs), + * hiding (is-kv-pairs, is-raw-array-of-rows), type * end @@ -88,7 +88,11 @@ fun empty-table(col-names :: List) -> Table: end end -fun table-from-raw-array(arr): +fun is-raw-array-of-rows(ra :: RawArray) -> Boolean: + raw-array-fold(lam(base, elt, _): base and is-row(elt) end, true, ra, 0) +end + +fun table-from-raw-array(arr :: RawArray%(is-raw-array-of-rows)) -> Table: col-names = raw-array-get(arr, 0).get-column-names() with-cols = empty-table(col-names) for raw-array-fold(t from with-cols, r from arr, _ from 0):