1
0
Fork 0
forked from fun/fun

Some more documentation fun about types. No code changes. (0.38.11)

This commit is contained in:
Johannes Findeisen 2026-02-11 08:46:43 +01:00
commit 988e9e4c27

View file

@ -153,20 +153,23 @@ print(typeof({})) // "map"
## Common patterns ## Common patterns
- Accumulate values: - Accumulate values:
`` -
```
acc = [] acc = []
for i = 0; i < 5; i = i + 1 { push(acc, i*i) } for i = 0; i < 5; i = i + 1 { push(acc, i*i) }
print(acc) // [0,1,4,9,16] print(acc) // [0,1,4,9,16]
`` ```
- Group related data with a map: - Group related data with a map:
`` -
```
person = { "name": "Lin", "skills": ["C", "Fun"] } person = { "name": "Lin", "skills": ["C", "Fun"] }
print(person["skills"][1]) // Fun print(person["skills"][1]) // Fun
``` ```
- Safe map read: - Safe map read:
`` -
```
v = person["twitter"] v = person["twitter"]
handle = v != nil ? v : "(none)" handle = v != nil ? v : "(none)"
print(handle) print(handle)
@ -175,7 +178,8 @@ print(typeof({})) // "map"
## Interop highlights ## Interop highlights
- JSON (optional module) maps JSON arrays to Fun arrays and JSON objects to Fun maps. - JSON (optional module) maps JSON arrays to Fun arrays and JSON objects to Fun maps.
``
```
#include <json/json.fun> #include <json/json.fun>
data = json_parse("{\"a\":[1,2]} ") data = json_parse("{\"a\":[1,2]} ")
print(typeof(data)) // map print(typeof(data)) // map