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
96
votes
3 answers

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
  • 9,173
  • 12
  • 35
  • 59
95
votes
11 answers

Getting the current date and or time in Elixir

This seems like a really dumb question but how does one get and display the current date or time in Elixir? I tried going through the docs but couldn't find anything. Do I need to use an Erlang function?
Graham Conzett
  • 8,344
  • 11
  • 55
  • 94
94
votes
16 answers

How to convert map keys from strings to atoms in Elixir

What is the way to convert %{"foo" => "bar"} to %{foo: "bar"} in Elixir?
NoDisplayName
  • 15,246
  • 12
  • 62
  • 98
85
votes
7 answers

Run shell commands in Elixir

I want to execute a program through my Elixir code. What is the method to call a shell command to a given string? Is there anything which isn't platform specific?
Lahiru
  • 2,609
  • 3
  • 18
  • 29
84
votes
2 answers

Elixir Sleep / Wait for 1 Second

How to sleep / wait for one second? Best I could find was something like this (in iex): IO.puts "foo" ; :timer.sleep(1); IO.puts "bar" But both of my puts happen with no delay.
newUserNameHere
  • 17,348
  • 18
  • 49
  • 79
81
votes
5 answers

Are Elixir variables really immutable?

In Dave Thomas's book Programming Elixir he states "Elixir enforces immutable data" and goes on to say: In Elixir, once a variable references a list such as [1,2,3], you know it will always reference those same values (until you rebind the…
Odhran Roche
  • 1,111
  • 1
  • 7
  • 14
80
votes
3 answers

In Elixir how do you initialize a struct with a map variable

I know its possible to create a struct via %User{ email: 'blah@blah.com' }. But if I had a variable params = %{email: 'blah@blah.com'} is there a way to create that struct using that variable for eg, %User{ params }. This gives an error, just…
bullfrog
  • 1,613
  • 1
  • 12
  • 13
78
votes
7 answers

How do I raise a number to a power in Elixir?

How can I calculate a number with an exponent in Elixir? For example, 23 would return 8.
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
76
votes
3 answers

How to create a map from a list of two item tuples in Elixir

What would be an elegant way for converting a list of two item tuples like [{1,2},{3,4}] into the map %{1=>2, 3=>4}? Keyword list would be trivial, but what if we have arbitrary keys?
siddhadev
  • 16,501
  • 2
  • 28
  • 35
73
votes
11 answers

Good IDE for Elixir

I am looking for an IDE that does atleast some of the following Code completion when typing variable names and possible functions after pressing . Show a functions signature and docs Navigate to the function/variable/module's definition It would…
Cristian Garcia
  • 9,630
  • 6
  • 54
  • 75
72
votes
6 answers

Debugging and debugging tools in Elixir?

I've just started using Elixir, and have started a Phoenix project, which I enjoy a lot. Now by having rails background, I'm used to being spoiled with debugging tools like "debugger", "byebug" and so on; I was wondering if there are any similar…
MartinElvar
  • 5,695
  • 6
  • 39
  • 56
72
votes
4 answers

In Elixir, is there any way to get a module to list its functions?

In the same way that we can get any object (or class) in Ruby to list its methods, is there any function in Elixir to list all functions belonging to a module? Something (at least remotely) like String.functions (where String could be replaced by…
iconoclast
  • 21,213
  • 15
  • 102
  • 138
70
votes
2 answers

How to Log something in Controller when Phoenix Server is running?

I'm trying to print some debug information from one of my Controllers in my Phoenix app when the server is running. defmodule PhoenixApp.TopicController do use PhoenixApp.Web, :controller def index(conn, _params) do log("this text") #…
Sheharyar
  • 73,588
  • 21
  • 168
  • 215
70
votes
4 answers

In Elixir's ExUnit, is it possible to just run one test?

In Python's nosetests you can just specify to run one test by calling its class followed by the test name. How can we do this with Elixir's ExUnit?
Muhammad Lukman Low
  • 8,177
  • 11
  • 44
  • 54
67
votes
3 answers

How do I recompile an Elixir project and reload it from within iex?

I'm currently learning Elixir by going through the OTP and mix tutorial on the elixir-lang website, and I'm having trouble finding out how to recompile and reload the project from within the shell. In Erlang I would do make:all([load]) and it would…
KallDrexx
  • 27,229
  • 33
  • 143
  • 254