Skip to content

Instantly share code, notes, and snippets.

View pcewing's full-sized avatar

Paul Ewing pcewing

  • Blizzard Entertainment
View GitHub Profile
@pcewing
pcewing / times.exs
Last active July 10, 2016 22:35
Macro Question
# Exercise: MacrosAndCodeEvaluation-2
# Write a macro called *times_n* that takes a single numeric argument. It should define a function
# called *times_n* in the caller's module that itself takes a single argument, and that multiplies
# the argument by *n*. So, calling *times_n(3)* should create a function called *times_3*, and
# calling *times_3(4)* should return 12. Here's an example of it in use:
#
# defmodule Test do
# require Times
# Times.times_n(3)
# Times.times_n(4)
@pcewing
pcewing / long_pattern_match.ex
Last active June 18, 2016 05:03
Formatting a function definition with long pattern matching/guard clauses.
# A message is supposed to come in like this but we don't know if the fields are filled out.
message = %{
route: %{
destination: "Tim",
source: "Paul"
},
type: :friend_request,
payload: %{
size: 32,
content: %{