Skip to content

Commit

Permalink
Add annotation for table-from-raw-array(), checking arg is indeed a raw
Browse files Browse the repository at this point in the history
array of rows brownplt#1758
  • Loading branch information
ds26gte committed Sep 9, 2024
1 parent 0620ea8 commit 9cc314b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/arr/trove/tables.arr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
provide:
* hiding (is-kv-pairs),
* hiding (is-kv-pairs, is-raw-array-of-rows),
type *
end

Expand Down Expand Up @@ -88,7 +88,11 @@ fun empty-table(col-names :: List<String>) -> Table:
end
end

fun table-from-raw-array(arr):
fun is-raw-array-of-rows(ra :: RawArray<Any>) -> Boolean:
raw-array-fold(lam(base, elt, _): base and is-row(elt) end, true, ra, 0)
end

fun table-from-raw-array(arr :: RawArray<Any>%(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):
Expand Down

0 comments on commit 9cc314b

Please sign in to comment.