Last active
February 18, 2023 22:28
-
-
Save enkr1/d245bb90512aa0e12fee3e8c0345dbb5 to your computer and use it in GitHub Desktop.
About Me (Elixir)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "[email protected]", | |
personal: "[email protected]" | |
}, | |
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