Questions tagged [elixir]

Elixir is an open-source, dynamic, compiled, general purpose functional programming language. It was designed to be fully compatible with the Erlang platform and is well suited to writing fault-tolerant, distributed applications with soft real-time guarantees and the ability for hot-code-swapping.

enter image description here

Elixir is an open-source, dynamic, compiled, general purpose functional programming language. It was designed to be fully compatible with the Erlang platform and is well suited to writing fault-tolerant, distributed applications with soft real-time guarantees and the ability for hot-code-swapping.

Elixir was designed with programmer productivity as a core concept and features:

  • Concise friendly syntax
  • Simple meta-programming with Macros
  • Scale facility and process orientation
  • Awesome documentation and testing built-in
  • Polymorphism with Protocols

Learning

Packages

Popular Elixir Projects

Books

Screencasts

Community

9482 questions
315
votes
9 answers

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, called using myfn.(param1, param2) Only the second…
Alex Marandon
  • 4,034
  • 2
  • 17
  • 21
233
votes
9 answers

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
  • 15,246
  • 12
  • 62
  • 98
192
votes
9 answers

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
  • 5,693
  • 4
  • 20
  • 26
175
votes
12 answers

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) >>> b =10 >>> type(b) I read in Elixir there are type checkers such as 'is_bitstring', 'is_float', 'is_list', 'is_map' etc, but what if you…
Muhammad Lukman Low
  • 8,177
  • 11
  • 44
  • 54
163
votes
6 answers

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 function and macros from other modules Looks like one…
User314159
  • 7,733
  • 9
  • 39
  • 63
123
votes
4 answers

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 pure Erlang or Elixir. I get the basic differences…
Saša Šijak
  • 8,717
  • 5
  • 47
  • 82
122
votes
8 answers

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
  • 2,609
  • 3
  • 18
  • 29
119
votes
1 answer

Where does Elixir/erlang fit into the microservices approach?

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 good toolset for managing them, I think that it's…
Papipo
  • 2,799
  • 2
  • 23
  • 28
115
votes
3 answers

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 also have Keyword Lists: > kl = [a: "one", b: "two"] # = [a:…
greggreg
  • 11,945
  • 6
  • 37
  • 52
106
votes
5 answers

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(["foo", "bar"], &(&1 == "foo")) != nil
ewH
  • 2,553
  • 2
  • 20
  • 13
100
votes
4 answers

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 database and models in a Phoenix app. I'm aware of…
Chase
  • 2,748
  • 2
  • 23
  • 32
99
votes
3 answers

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")) ...(3)> end ...(3)> ) ...(3)> ' ...(3)> end …
4d2025
  • 1,013
  • 1
  • 7
  • 5
98
votes
4 answers

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 difference is in intention. .ex files are meant to be …
Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
97
votes
2 answers

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 new (conn, _params) do ... end The book had me…
Andrew Hendrie
  • 6,205
  • 4
  • 40
  • 71
97
votes
2 answers

How to run an Elixir application?

What is the correct way to run an Elixir application? I'm creating a simple project by: mix new app and after that I can do: mix run which basically compiles my app once. So when I add: IO.puts "running" in lib/app.ex I see "running" only for the…
Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90
1
2 3
99 100