Skip to main content
Filter by
Sorted by
Tagged with
316 votes
9 answers
33k views

Why are there two kinds of functions in Elixir?

I'm learning Elixir and wonder why it has two types of function definitions: functions defined in a module with def, called using myfunction(param1, param2) anonymous functions defined with fn, ...
Alex Marandon's user avatar
237 votes
10 answers
40k views

How can I schedule code to run every few hours in Elixir or Phoenix framework?

So let's say I want to send a bunch of emails or recreate sitemap or whatever every 4 hours, how would I do that in Phoenix or just with Elixir?
NoDisplayName's user avatar
195 votes
10 answers
123k views

How to join strings in Elixir?

How do I join two strings in a list with a space, like: ["StringA", "StringB"] becomes "StringA StringB"
thiagofm's user avatar
  • 5,863
176 votes
12 answers
121k views

How do you check for the type of variable in Elixir

In Elixir how do you check for type such as in Python: >>> a = "test" >>> type(a) <type 'str'> >>> b =10 >>> type(b) <type 'int'> I read in Elixir ...
Muhammad Lukman Low's user avatar
164 votes
6 answers
32k views

Elixir: use vs import

What's the difference between use and import? use is a simple mechanism for using a given module into the current context https://hexdocs.pm/elixir/Kernel.SpecialForms.html#import/2 Imports ...
User314159's user avatar
  • 7,955
129 votes
5 answers
44k views

Are there things Elixir can do that Erlang cannot, or vice versa?

This question is in the context of the Beam VM and the capabilities that it provides, not in the general context of what a Turing complete language can do. I want to invest some time to learn either ...
Saša Šijak's user avatar
  • 9,163
125 votes
9 answers
120k views

Convert Elixir string to integer or float

I need to convert a string to a floating point value or an integer. There was no method such as, string_to_integer
Lahiru's user avatar
  • 2,646
119 votes
1 answer
14k views

Where does Elixir/erlang fit into the microservices approach? [closed]

Lately I've been doing some experiments with docker compose in order to deploy multiple collaborating microservices. I can see the many benefits that microservices provide, and now that there is a ...
Papipo's user avatar
  • 2,799
117 votes
3 answers
12k views

What is the benefit of Keyword Lists?

In elixir we have Maps: > map = %{:a => "one", :b => "two"} # = %{a: "one", b: "two"} > map.a # = "one" > map[:a] # = "one" We ...
greggreg's user avatar
  • 12.1k
110 votes
5 answers
102k views

How to check if an item exists in an Elixir list or tuple?

This is seemingly simple, but I can't seem to find it in the docs. I need to simply return true or false if an item exists in a list or tuple. Is Enum.find/3 really the best way to do this? Enum.find(...
ewH's user avatar
  • 2,643
105 votes
3 answers
14k views

IEx - How to cancel multiline command?

When I use IEx and make a typo like additional bracket or ", then most of the time I get a syntax error. But there are cases like this one: iex(3)> Enum.each '12345', &(IO.puts(&1")) ....
4d2025's user avatar
  • 1,073
104 votes
4 answers
29k views

Elixir: When to use .ex and when .exs files

Elixir's documentation states that In addition to the Elixir file extension .ex, Elixir also supports .exs files for scripting. Elixir treats both files exactly the same way, the only ...
Ole Spaarmann's user avatar
104 votes
4 answers
24k views

Is there a Phoenix equivalent to Rails Console

I'm just learning Phoenix and Elixir and I'm coming from Ruby/Rails where I work in the REPL using pry to inspect my database and application state. I'm trying to figure out how to interact with my ...
Chase's user avatar
  • 2,826
103 votes
3 answers
72k views

How to generate a random number in Elixir?

I need to generate a random number. I found the Enum.random/1 function, but it expects an enumerable such as a list or range of numbers. Is that the only way to get a random number?
Sergio Tapia's user avatar
  • 9,753
102 votes
2 answers
28k views

What's the difference between `def` and `defp`

I'm going through the Programming Phoenix book and I am wondering what the difference between def and defp is. There are several functions in my controller - most of them are actions like this: def ...
Andrew Hendrie's user avatar

15 30 50 per page
1
2 3 4 5
641