-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial: Types: ARR SEQ MAP
Backed by Scala's Vector
, ARR
is a general-purpose collection analogue to
lists/arrays in other languages.
Empty ARR
is falsy; all other ARR
s are truthy.
[1 2 3 4]
[8 "asdf" ( 1+ 3* )]
[[1 2 [3 4]] 5 6]
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 SEQ
s 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
is a collection of key-value pairs backed by Scala's VectorMap
. Length-2
ARR
s represent each key-value pair, which is automatically collected inside
[
]:
. MAP
s preserve insertion order.
Empty MAP
is falsy; all other MAP
s 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 MAP
s 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
Made with ❤️ by Ben Pang (@molarmanful).