-
-
Notifications
You must be signed in to change notification settings - Fork 4
map
map = “data”
The fundamental data type in Wasp is a tree of nodes, represented as nested map of maps.
Just like how in lisp everything is a list, in angle everything is a map.
Or internally: a node with parent, children and values.
Peter{address="Home 1"}
is internally represented as
Node{
name="Peter"
children={
Node{
name="address "
value=Node{
name="Home 1"
type=string
}
}
}
null values are omitted
The map functor of other programing languages is not necessary because it is a first class citizen:
All functions are automatically broadcasting on lists and pair values:
square number=number*number
square [1 2 3] == [1 4 9]
square [a:1 b:2 c:3] == [a:1 b:4 c:9]
delete file := run `rm $file.name`
delete all files in ls / # 🧐
Even though the map functor is part of angle, in 99% situations it should be superfluous via all/iteration as seen above.
similarly, applying a map is one of the most fundamental operations.
The rust match element map
functor will be supported but may still be too verbose if used very often.
There is possibly ambiguity with adopting math notation though f={a:1 b:2} f(a) == 1
. This MAY be resolved by reading f(a=2) and f(a) very differently, because in the current scheme f(a=2) == {a:2 b:3}
or worse f(a=2)==3, because the last expression of the block is returned todo.
A tree in wasp is just a nested map. The nodes may be keys or data.
It's obvious that one of the biggest shortcommings of classical lisps is that there is no standard first class citizen integration of maps.
However Clojure maps, Fennel tables and Janet structs/tables at least partially address this issue:
https://clojure.org/guides/learn/hashed_colls#_maps