-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create/publish an Elixir package on Hex.pm #95
Comments
Create a Mix Project and Run Elixir Codehttps://pragmaticstudio.com/tutorials/create-elixir-mix-project-and-run-code This is a good intro to using |
Decided I didn't need to introduce the complexity at this stage. 😕 Meanwhile I've found a way of testing |
TIL: how to pass a function as a parameter in Elixir:https://stackoverflow.com/questions/22562192/how-do-you-pass-a-function-as-a-parameter-in-elixir Use For example: def my_hof(f) # "hof" = higher order function (in case you're wondering...)
f.([1, 2, 3], &(&1 * 2))
end
my_hof(&Enum.map/2) in my example I modified the code from: # This recursive function calls Quotes.random until a quote is repeated
def get_random_quote_until_collision(random_quotes_list) do
random_quote = Quotes.random()
if Enum.member?(random_quotes_list, random_quote) do
random_quotes_list
else
get_random_quote_until_collision([random_quote | random_quotes_list])
end
end
test "Quotes.random returns a random quote" do
# execute Quotes.random and accumulate until a collision occurs
random_quotes_list = get_random_quote_until_collision([])
# this is the birthday paradox at work! ;-)
# IO.inspect Enum.count(random_quotes_list)
assert Enum.count(random_quotes_list) < 200
end To: # This recursive function calls func (argument) until a quote is repeated
def get_quotes_until_collision(random_quotes_list, func) do
random_quote = func.()
if Enum.member?(random_quotes_list, random_quote) do
random_quotes_list
else
get_quotes_until_collision([random_quote | random_quotes_list], func)
end
end
test "Quotes.random returns a random quote" do
# execute Quotes.random and accumulate until a collision occurs
random_quotes_list = get_quotes_until_collision([], &Quotes.random/0)
# this is the birthday paradox at work! ;-)
# IO.inspect Enum.count(random_quotes_list)
assert Enum.count(random_quotes_list) < 200
end |
I've written 5k words in https://github.com/dwyl/learn-elixir/blob/code-reuse-publishing-to-hexpm-issue%2395/code-reuse-hexpm.md and https://github.com/dwyl/quotes and I feel it's close to being finished ... but I need to work on something
|
where quotes Hex package is used #95
Used the |
…e#95 Code reuse publishing to hexpm issue #95
GOTO: /code-reuse-hexpm.md |
…e#95 PR: Code Reuse Publishing to Hex.pm issue #95 & 183
We don't have a beginner-friendly write-up for creating Hex.pm packages; we need a concise guide.GOTO: /code-reuse-hexpm.md
Todo:Done!Consolidate these:
How to Use the Package Locally Before Publishing it to
hex.pm
The text was updated successfully, but these errors were encountered: