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
67
votes
7 answers

Erlang Processes vs Java Threads

I am reading "Elixir in Action" book by Saša Jurić, and in the first chapter it says: Erlang processes are completely isolated from each other. They share no memory, and a crash of one process doesn’t cause a crash of other processes. Isn't…
Wand Maker
  • 18,476
  • 8
  • 53
  • 87
66
votes
5 answers

Add new element to list

I was trying to add a new element into a list as follow: iex(8)> l = [3,5,7,7,8] ++ 3 [3, 5, 7, 7, 8 | 3] iex(9)> l [3, 5, 7, 7, 8 | 3] Why did I get on the 5th position like 8 | 3 What it does mean? And how can I add new element to the…
softshipper
  • 32,463
  • 51
  • 192
  • 400
66
votes
3 answers

Pattern match function against empty map

I'm playing around with pattern match and I found out, that it's not quite easy to pattern match parameters of a method against an empty map. I thought it would go something like this: defmodule PatternMatch do def modify(%{}) do %{} end …
leifg
  • 8,668
  • 13
  • 53
  • 79
66
votes
2 answers

How to use IO.inspect on a long list without trimming it?

When I do: IO.inspect [:right, :top, :left, ...very_long_list] I only get the first items (it's a list of moves to solve a 15-puzzle) like this: [:right, :top, :left, :bot, :bot, :left, :top, :top, :right, :right, :bot, :left, :bot, :left, :top,…
ItsASecret
  • 2,589
  • 3
  • 19
  • 32
66
votes
5 answers

In Elixir, how can a range be converted to a list?

I can declare a range as follows: range = 1..10 Is there a way to convert the range to a list?
epotter
  • 7,631
  • 7
  • 63
  • 88
65
votes
2 answers

How can I make Mix run only specific tests from my suite of tests?

How can I make Mix run only specific tests from my suite of tests? When running mix test all tests are executed
robkuz
  • 9,488
  • 5
  • 29
  • 50
64
votes
5 answers

Simulate ternary operator in Elixir

How to do the similar conditional one-line check in Elixir? if (x > 0) ? x : nil Is this the only equivalent in elixir world? if true, do: 1, else: 2
Teo Choong Ping
  • 12,512
  • 18
  • 64
  • 91
64
votes
4 answers

Is there a way to test private functions in modules in ExUnit of Elixir?

Functions defined by defp aren't exported so I can't execute them in places other than in the module.
Noah Blues
  • 1,339
  • 2
  • 11
  • 19
62
votes
6 answers

Turn postgres date representation into ISO 8601 string

I'm trying to format a Postgres date representation into a ISO 8601 string. I'm assuming that there is a Postgres function that can do it, but I found the documentation short on examples. My query is SELECT now()::timestamp which…
CallMeNorm
  • 2,299
  • 1
  • 16
  • 23
60
votes
6 answers

How do you define constants in Elixir modules?

In Ruby, if one were defining constants in classes, they would define them using all caps. For example: class MyClass MY_FAVORITE_NUMBER = 13 end How do you do this in Elixir? And if no such equivalent exists, how do you get around the problem of…
Martimatix
  • 1,553
  • 1
  • 15
  • 18
60
votes
1 answer

In what sense are languages like Elixir and Julia homoiconic?

Homoiconicity in Lisp is easy to see: (+ 1 2) is both the function call to + with 1, 2 as arguments, as well as being a list containing +, 1, and 2. It is simultaneously both code and data. In a language like Julia, though: 1 + 2 I know we can…
user2666425
  • 1,671
  • 1
  • 15
  • 21
59
votes
1 answer

How do you pass a function as a parameter in Elixir?

How do you specify a function as a parameter to another function in Elixir? For instance, pass foo to bar so that bar can then call foo. What is the syntax both in the calling function and the function that receives it?
Matt
  • 84,419
  • 25
  • 57
  • 67
58
votes
3 answers

Elixir lists interpreted as char lists

I'm just starting out with Elixir. I'm writing some tests using ExUnit for simple Enumerable functions that I am implementing myself, without using the standard Enum module. In my tests I'm finding that whenever I reference the list [7, 8, 9], once…
George Taveras
  • 590
  • 1
  • 4
  • 5
58
votes
2 answers

Pry while testing

I'm pretty new in Elixir, but have a lot fun with it! I came from Ruby world, so start looking analogy. And there is exist debugging tool pry. Using binding.pry I can interrupt any session. I found something similar in Elixir – IEx.pry. But it…
Dmitriy
  • 1,422
  • 15
  • 27
57
votes
5 answers

How to read config variable in Phoenix / Elixir?

I'd like to set the title of my app in my/config/config.exs file: config :my, My.Endpoint, url: [host: "localhost"], root: Path.dirname(__DIR__), secret_key_base: "secret", title: "My App" How can I read title later to use it in template?…
Alex Craft
  • 13,598
  • 11
  • 69
  • 133