Branch
Hash :
6244fe3b
Author :
Thomas de Grivel
Date :
2025-10-21T18:32:49
Make doc
KC3 maps are like Elixir maps, they are key-values enclosed in %{}.
ikc3> a = %{id: 1, title: "My title", message: "Hello, world !"}
%{id: 1,
title: "My title",
message: "Hello, world !"}
Destructuring works with maps to extract values.
ikc3> %{id: id, title: "My title", message: message} = ^ a
%{id: 1,
title: "My title",
message: "Hello, world !"}
ikc3> id
1
ikc3> message
"Hello, world !"
You can use the dot syntax to access map values from a Sym key.
ikc3> a = %{id: 1, title: "My title", message: "Hello, world !"}
%{id: 1,
title: "My title",
message: "Hello, world !"}
ikc3> a.id
1
ikc3> a.message
"Hello, world !"
The bracket syntax allows you to query any key type.
ikc3> a[:id]
1
ikc3> a[:message]
"Hello, world !"
You can also use the KC3.access function for the same result.
ikc3> a = %{id: 1, title: "My title", message: "Hello, world !"}
%{id: 1,
title: "My title",
message: "Hello, world !"}
ikc3> access(a, [:id])
1
ikc3> access(a, [:message])
"Hello, world !"
To update an existing map you can use Map.put like this.
ikc3> a = %{id: 1, title: "My title"}
%{id: 1,
title: "My title"}
ikc3> a = Map.put(a, :message, "Hello, world !")
%{id: 1,
title: "My title",
message: "Hello, world !"}
Top : KC3 documentation
Previous : 1.15 List
Next : 1.17 Ptr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
# 1.16 Map
KC3 maps are like Elixir maps, they are key-values enclosed in `%{}`.
```elixir
ikc3> a = %{id: 1, title: "My title", message: "Hello, world !"}
%{id: 1,
title: "My title",
message: "Hello, world !"}
```
Destructuring works with maps to extract values.
```elixir
ikc3> %{id: id, title: "My title", message: message} = ^ a
%{id: 1,
title: "My title",
message: "Hello, world !"}
ikc3> id
1
ikc3> message
"Hello, world !"
```
You can use the dot syntax to access map values from a `Sym` key.
```elixir
ikc3> a = %{id: 1, title: "My title", message: "Hello, world !"}
%{id: 1,
title: "My title",
message: "Hello, world !"}
ikc3> a.id
1
ikc3> a.message
"Hello, world !"
```
The bracket syntax allows you to query any key type.
```elixir
ikc3> a[:id]
1
ikc3> a[:message]
"Hello, world !"
```
You can also use the `KC3.access` function for the same result.
```elixir
ikc3> a = %{id: 1, title: "My title", message: "Hello, world !"}
%{id: 1,
title: "My title",
message: "Hello, world !"}
ikc3> access(a, [:id])
1
ikc3> access(a, [:message])
"Hello, world !"
```
To update an existing map you can use Map.put like this.
```elixir
ikc3> a = %{id: 1, title: "My title"}
%{id: 1,
title: "My title"}
ikc3> a = Map.put(a, :message, "Hello, world !")
%{id: 1,
title: "My title",
message: "Hello, world !"}
```
---
Top : [KC3 documentation](../)
Previous : [1.15 List](1.15_List)
Next : [1.17 Ptr](1.17_Ptr)