Add Map.from_struct and Kernel.struct to maps section of Elixir cheatsheet (#1631)
* Update elixir.md Added Map.from_struct and Kernel.struct to maps section. * Update elixir.md Co-authored-by: Rico Sta. Cruz <rstacruz@users.noreply.github.com>
This commit is contained in:
parent
4d47cbd4e9
commit
c1de0e223c
14
elixir.md
14
elixir.md
|
@ -429,6 +429,20 @@ Map.new([a: 1, b: 2])
|
|||
Map.new([:a, :b], fn x -> {x, x} end) # → %{a: :a, b: :b}
|
||||
```
|
||||
|
||||
### Working with structs
|
||||
|
||||
#### Struct to map
|
||||
|
||||
```elixir
|
||||
Map.from_struct(%AnyStruct{a: "b"}) # → %{a: "b"}
|
||||
```
|
||||
|
||||
#### Map to struct
|
||||
|
||||
```elixir
|
||||
struct(AnyStruct, %{a: "b"}) # → %AnyStruct{a: "b"}
|
||||
```
|
||||
|
||||
## List
|
||||
|
||||
```elixir
|
||||
|
|
Loading…
Reference in New Issue