Constructors

Functions that construct a table.

table

table { "a" } { 1 2 } |type?
; returns table
table { 'a } { 1 2 } |type?
; returns table

table\columns

table\columns { "a" } { { 1 2 3 } } |type?
; returns table
table\columns { "a" "b" } { { 1 2 3 } { 4 5 6 } } |length?
; returns 3

table\rows

table\rows { 'a 'b } { { 1 2 } { 3 4 } }
; returns table { "a" "b" } [ 1 2 3 4 ]
table\rows { 'a 'b } list [ list [ 1 2 ] list [ 3 4 ] ] |type?
; returns table

to-table

to-table list [ dict { "a" 1 } dict { "a" 2 } ] |type?
; returns table
to-table list [ dict { "a" 1 "b" "Jim" } dict { "a" 2 "b" "Bob" } ] |header? |sort
; returns list { "a" "b" }
to-table list [ dict { "a" 1 "b" "Jim" } dict { "a" 2 "b" "Bob" } ] |column? "b" |first
; returns "Jim"

Filtering

Functions that construct a table.

where-equal

table { 'a } { 1 2 3 2 } |where-equal "a" 2 |length?
; returns 2

where-void

table { 'a } { 1 _ 3 _ } |where-void "a" |length?
; returns 2

where-match

table { 'a } { "1" "2" "a3" "2b" } |where-match 'a regexp "^[0-9]$" |length?
; returns 2

where-contains

table { 'a } { "1" "2" "a3" "2b" } |where-contains 'a "2" |length?
; returns 2

where-not-contains

table { 'a } { "1" "2" "a3" "2b" } |where-not-contains 'a "3" |length?
; returns 3

where-greater

table { 'a } { 1 2 3 2 } |where-greater 'a 1 |length?
; returns 3

where-lesser

table { 'a } { 1 2 3 2 } |where-lesser 'a 3 |length?
; returns 3

where-between

table { 'a } { 1 2 3 2 } |where-between 'a 1 3 |length?
; returns 2

where-between\inclusive

table { 'a } { 1 2 3 2 5 } |where-between\inclusive 'a 2 3 |length?
; returns 3

where-in

table { "name" "age" } { "Enno" 30 "Enya" 25 "Bob" 19 } |where-in 'name { "Enno" "Enya" "Roger" } |column? "age"
; returns { 30 25 }

Row level functions

Functions that construct a table.

add-row

table { "a" "b" } { 6 60 7 70 } |add-row { 8 80 } |-> 2 |-> "b"
; returns 80

get-rows

table { "a" "b" } { 6 60 7 70 } |get-rows |type?
; returns native

add-rows

ref table { "a" "b" } { 6 60 7 70 } :sheet sheet .deref |add-rows [ 3 30 ] |length?
; returns 3
ref table { "a" "b" } { 1 80 2 90 } :sheet sheet .deref |add-rows { 3 30 } |length?
; returns 3

add-rows!

ref table { "a" "b" } { 1 10 2 20 } :sheet sheet .add-rows! [ 3 30 ] sheet .deref .length?
; returns 3

update-row!

spr1: ref table { "a" "b" } { 1 10 2 20 } spr1 .update-row! 1 dict [ "a" 111 ] spr1 .deref .A1
; returns 111
spr1: ref table { "a" "b" } { 1 10 2 20 } incrA: fn { row } { row + [ "a" ( "a" <- row ) + 9 ] } update-row! spr1 1 ?incrA spr1 |deref |A1
; returns 10

remove-row!

spr1: ref table { "a" "b" } { 1 10 2 20 } spr1 .remove-row! 1 spr1 .deref .A1
; returns 2

Column level functions

Functions that construct a table.

columns?

table { "name" "age" "job_title" } { "Bob" 25 "Janitor" "Alice" 29 } |columns? { 'name 'age } |header?
; returns list { "name" "age" }

header?

table { "age" "name" } { 123 "Jim" 29 "Anne" } |header?
; returns list { "age" "name" }

column?

table { "name" "age" "job_title" } { "Bob" 25 "Janitor" "Alice" 29 "Teacher" } |column? 'name
; returns { "Bob" "Alice" }

drop-column

table { "name" "age" "job_title" } { "Bob" 25 "Janitor" "Alice" 29 "Librarian" } |drop-column "name" |header?
; returns list { "age" "job_title" }

rename-column!

tab: ref table { "name" "age" } { "Bob" 25 "Alice" 29 "Charlie" 19 } tab .rename-column! "name" "first_name" , tab .header?
; returns list { "first_name" "age" }

add-column

table { "name" "age" } { "Bob" 25 "Alice" 29 "Charlie" 19 } |add-column 'job { } { "Cook" } |column? "job"
; returns { "Cook" "Cook" "Cook" }

Miscelaneous

order-by!

tab: table { "name" "age" } { "Bob" 25 "Alice" 29 "Charlie" 19 } tab .order-by! 'age 'asc |column? "age"
; returns { 19 25 29 }

order-by

tab: table { "name" "age" } { "Bob" 25 "Alice" 29 "Charlie" 19 } |order-by 'age 'desc |column? "age"
; returns { 29 25 19 }

add-indexes!

table { "name" "age" } { "Bob" 25 "Alice" 29 "Charlie" 19 } |add-indexes! { name } |indexes?
; returns { "name" }

indexes?

table { "name" "age" } { "Bob" 25 "Alice" 29 "Charlie" 19 } |add-indexes! { name age } |indexes?
; returns { "name" "age" }

autotype

table { "age" } { 123 29 19 } |autotype 1 |types?
; returns { integer }

left-join

names: table { "id" "name" } { 1 "Paul" 2 "Chani" 3 "Vladimir" } , houses: table { "id" "house" } { 1 "Atreides" 3 "Harkonnen" } , names .inner-join houses 'id 'id |header?
; returns list { "id" "name" "id_2" "house" }
names: table { "id" "name" } { 1 "Paul" 2 "Chani" 3 "Vladimir" } , houses: table { "id" "house" } { 1 "Atreides" 3 "Harkonnen" } , names .left-join houses 'id 'id |column? "name"
; returns { "Paul" "Chani" "Vladimir" }

inner-join

names: table { "id" "name" } { 1 "Paul" 2 "Chani" 3 "Vladimir" } , houses: table { "id" "house" } { 1 "Atreides" 3 "Harkonnen" } , names .inner-join houses 'id 'id |header?
; returns list { "id" "name" "id_2" "house" }
names: table { "id" "name" } { 1 "Paul" 2 "Chani" 3 "Vladimir" } , houses: table { "id" "house" } { 1 "Atreides" 3 "Harkonnen" } , names .inner-join houses 'id 'id |column? "name"
; returns { "Paul" "Vladimir" }

group-by

table { "name" "val" } { "a" 1 "b" 6 "a" 5 "b" 10 "a" 7 } |group-by 'name { 'name count 'val sum } |column? "val_sum" |sort
; returns { 13 16 }
table { "name" "val" } { "a" 1 "b" 6 "a" 5 "b" 10 "a" 7 } |group-by 'name { 'name count 'val min } |column? "val_min" |sort
; returns { 1 6 }
table { "name" "val" } { "a" 1 "b" 6 "a" 5 "b" 10 "a" 12 } |group-by 'name { 'name count 'val avg } |column? "val_avg" |sort
; returns { 6 8 }

A1

table { 'a } { 123 234 345 } |A1
; returns 123

B1

table { 'a 'b } { 123 234 345 456 } |B1
; returns 234

A2

table { 'a 'b } { 123 234 345 456 } |A2
; returns 345

B2

table { 'a 'b } { 123 234 345 456 } |B2
; returns 456

Loading and saving

Functions that construct a table.

load\csv

cc os f:: mktmp + "/test.csv" spr1:: table { "a" "b" "c" } { 1 1.1 "a" 2 2.2 "b" 3 3.3 "c" } spr1 .save\csv f spr2:: load\csv f |autotype 1 spr1 = spr2
; returns 1

load\tsv

cc os f:: mktmp + "/test.tsv" spr1:: table { "a" "b" "c" } { 1 1.1 "a" 2 2.2 "b" 3 3.3 "c" } spr1 .save\tsv f spr2:: load\tsv f |autotype 1 spr1 = spr2
; returns 1

save\csv

cc os f:: mktmp + "/test.csv" spr1:: table { "a" "b" "c" } { 1 1.1 "a" 2 2.2 "b" 3 3.3 "c" } spr1 .save\csv f spr2:: load\csv f |autotype 1 spr1 = spr2
; returns 1

save\tsv

cc os f:: mktmp + "/test.csv" spr1:: table { "a" "b" "c" } { 1 1.1 "a" 2 2.2 "b" 3 3.3 "c" } spr1 .save\tsv f spr2:: load\tsv f |autotype 1 spr1 = spr2
; returns 1

load\xlsx

cc os f:: mktmp + "/test.xlsx" spr1:: table { "a" "b" "c" } { 1 1.1 "a" 2 2.2 "b" 3 3.3 "c" } spr1 .save\xlsx f spr2:: load\xlsx f |autotype 1 spr1 = spr2
; returns 1

save\xlsx

cc os f:: mktmp + "/test.xlsx" spr1:: table { "a" "b" "c" } { 1 1.1 "a" 2 2.2 "b" 3 3.3 "c" } spr1 .save\xlsx f spr2:: load\xlsx f |autotype 1 spr1 = spr2
; returns 1