OSDN Git Service

Regular updates
authorErik <erikgronwal@users.osdn.me>
Tue, 16 Mar 2021 14:55:05 +0000 (23:55 +0900)
committerErik <erikgronwal@users.osdn.me>
Tue, 16 Mar 2021 14:55:05 +0000 (23:55 +0900)
elixir.md

index 48816e2..3928228 100644 (file)
--- a/elixir.md
+++ b/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