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

How to use the "with" keyword in Elixir and what is it for?

In elixir 1.2 they've included the keyword "with", but it's not completely clear to me what it is for. How and in which situation would I use it?
diogovk
  • 2,108
  • 2
  • 19
  • 24
56
votes
1 answer

Catch-all/wildcard route in Elixir's Phoenix?

In the Phoenix router is there a route that could act as a wildcard?
Jason G
  • 916
  • 9
  • 14
56
votes
2 answers

How to alter a column name in an Ecto model with a migration?

Does anyone know of (or can provide) an example of how to alter a table column name using the ecto DSL I'm guessing I just use mix ecto.gen.migration but then would I just fill in the empty created file with my custom code (if so, how would you edit…
TheStoneFox
  • 3,007
  • 3
  • 31
  • 47
56
votes
2 answers

How to connect two Elixir nodes via local network?

How can I connect two Erlang/Elixir-nodes of two different machines via network connection?
ChaosSteffen
  • 663
  • 1
  • 5
  • 6
55
votes
4 answers

Elixir convert struct to map

I'm trying to convert a struct to a map to be able to clean all the nil values I'm currently using this code case Nadia.get_updates do {:ok, results} -> Map.from_struct(results) |> Enum.filter(fn {_, v} -> v != nil end) |>…
user2070502
  • 603
  • 1
  • 5
  • 8
55
votes
6 answers

Lists vs. Tuples - What to use and when?

I am trying to grasp the difference between Lists and Tuples in Elixir. From the Basic Types section of Elixir Guides, I understand that: Lists are stored as Linked Items Updating a List is fast (only when prepending) Fetching List items is…
Sheharyar
  • 73,588
  • 21
  • 168
  • 215
52
votes
3 answers

Difference between protocol & behaviour in elixir

Behaviours define callbacks & protocols define methods without signatures. Modules implementing a protocol should give definition for all those methods. Same for modules using a behaviour. What is the semantic difference? One difference I can think…
Aravindh S
  • 1,185
  • 11
  • 19
50
votes
8 answers

How to use raw sql with ecto Repo

I have an upsert requirement, so I need to call a postgres stored procedure or use a common table expression. I also use the pgcrypto exgtension for passwords and would like to use postgres functions (such as "crypt" to encode/decode…
Krut
  • 4,112
  • 3
  • 34
  • 42
49
votes
2 answers

How to rollback, reset, or drop Ecto test database?

Usually mix.test cleans the test database, but it is not working. It may be because I was playing around with making a users schema, but didn't want to use what I made so I got rid of it. I then started over and made a new schema for users which…
Katherine
  • 2,086
  • 1
  • 14
  • 23
48
votes
4 answers

How can I see the raw SQL generated for an Ecto.Query?

I have an Ecto.Query and a Repo, such that I can call Repo.all(query) and get results. However, the results are not what I expect. How can I see the raw SQL the Repo will generate from the Ecto.Query?
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
48
votes
2 answers

How can we easily time function calls in elixir?

How can we easily time function calls in Elixir? Is there any hidden switch in IEx to enable this?
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157
47
votes
5 answers

Elixir - try/catch vs try/rescue?

Background Both try/rescue and try/catch are error handling techniques in Elixir. According the corresponding chapter in the introduction guide. Errors can be rescued using the try/rescue construct On the other hand, throw and catch are reserved…
Gavin
  • 4,458
  • 3
  • 24
  • 37
47
votes
3 answers

Add / Remove key-value pairs from a Map

How to add (and remove) key-value pairs in an Elixir map? This does not work: map = %{a: 1, b: 2, c: 3} map[:d] = 4
Sheharyar
  • 73,588
  • 21
  • 168
  • 215
47
votes
2 answers

Regular Expressions in Elixir case

Can you use a Regular Expression inside a case in Elixir? So something along the lines of this: case some_string do "string" -> # do something ~r/string[\d]+/ -> # do something _ -> # do something end
Daisuke Shimamoto
  • 5,206
  • 6
  • 32
  • 37
47
votes
3 answers

What are Elixir Bang Functions?

I first noticed a function with a trailing exclamation-mark/bang(!) while going through the Phoenix tutorial (in the Incoming Events section) def handle_in("new_msg", %{"body" => body}, socket) do broadcast! socket, "new_msg", %{body: body} …
Marc
  • 4,820
  • 3
  • 38
  • 36