Skip to content

Instantly share code, notes, and snippets.

@enkr1
Last active February 18, 2023 22:28
Show Gist options
  • Save enkr1/d245bb90512aa0e12fee3e8c0345dbb5 to your computer and use it in GitHub Desktop.
Save enkr1/d245bb90512aa0e12fee3e8c0345dbb5 to your computer and use it in GitHub Desktop.
About Me (Elixir)
defmodule User do
use MapSet
defstruct [
:first_name,
:last_name,
:bio,
:email,
:roles,
:interests,
:inserted_at
]
def create(attrs) do
%__MODULE__{ attrs | interests: MapSet.new(attrs.interests) }
|> set_daily_routine(["code", "workout", "game", "beatbox", "sleep"])
end
defp set_daily_routine(user, activities) do
Enum.reduce(activities, user, &MapSet.put(&2, &1))
end
end
def user_attrs do
%{
first_name: "Jing Hui",
last_name: "PANG",
bio: "I'm in love with Elixir right now",
email: %{
work: "enkr99@gmail.com",
personal: "jinghuipang99@gmail.com"
},
roles: [
%{title: "Software Engineer", inserted_at: ~N[2020-09-14 09:30:00]},
%{title: "Beatboxer", inserted_at: ~N[2016-12-01 00:00:00]}
],
interests: [
%{title: "Coding!"},
%{title: "Working out"},
%{title: "Beatboxing"},
%{title: "Sleeping ... :skull:"}
],
inserted_at: ~N[1999-12-06 00:00:00]
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment