Skip to content

Tutorial: Types: ARR SEQ MAP

molarmanful edited this page Nov 4, 2023 · 8 revisions

ARR

Backed by Scala's Vector, ARR is a general-purpose collection analogue to lists/arrays in other languages.

Empty ARR is falsy; all other ARRs are truthy.

[1 2 3 4]
[8 "asdf" ( 1+ 3* )]
[[1 2 [3 4]] 5 6]

SEQ

Unlike ARR, SEQ is a lazy collection backed by Scala's LazyList, meaning that computations on SEQ do not execute until necessary. This allows for abstract representations of large or even infinite lists - at the minor inconvenience of not being able to directly view the computations.

Empty SEQ is falsy; all other SEQs are truthy.

$W
1rep

A common pattern to get an idea of what's in the SEQ is to use tk ("take") and >A ("to ARR"):

$W 10tk >A
=> [0 1 2 3 4 5 6 7 8 9]

MAP

MAP is a collection of key-value pairs backed by Scala's VectorMap. Length-2 ARRs represent each key-value pair, which is automatically collected inside [ ]:. MAPs preserve insertion order.

Empty MAP is falsy; all other MAPs are truthy.

[ ["a" 1] ["b" 2] ["c" 3] ]:
[ "a" 1, "b" 2, "c" 3, ]:

A multiline version that is potentially more readable:

[.
  "a" 1 ,.
  "b" 2 ,.
  "c" 3 ,.
]:

Multiline strings can also parse into MAPs using >>M. After each line executes, the top 2 items on each iteration's stack become the key-value pair.

`>>M
  "a" 1
  "b" 2
  "c" 3
>>M