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
5
votes
1 answer

When to use compile-only dependencies in Elixir

When would it be appropriate to specify a dependency only in deps in my mix.exs and not as a runtime dependency in applications? I thought that applications are actual applications that need to be started before my own application can be started,…
Paweł Obrok
  • 22,568
  • 8
  • 74
  • 70
5
votes
2 answers

Elixir ecto connect to an existing DB

After doing some research in the link below https://github.com/elixir-lang/ecto/tree/master/examples/simple I am a little confused about how to use ecto in elixir. There is always a schema declared like defmodule Weather do use Ecto.Model …
王志軍
  • 1,021
  • 1
  • 11
  • 21
5
votes
2 answers

How to pack / unpack a hex string (high nibble first) with Elixir

I was wondering how I would work with hex strings in Elixir. Specifically, I'm interested in converting from Hex to ASCII. In Ruby, an implementation of this may be: ["001C7F616A8B002128C1A33E8100"].pack('H*').gsub(/[^[:print:]]/, '.') How would I…
kkirsche
  • 1,217
  • 2
  • 15
  • 38
5
votes
1 answer

Is it possible to stub(mock?) Ecto.UUID.generate in an ExUnit test?

I'm using Ecto.UUID.generate to create a random token on a user model. In my ExUnit test, I want to test the controller that calls the creation route, however because the token is always random, I can't deterministically test the result. Ideally, I…
TheStoneFox
  • 3,007
  • 3
  • 31
  • 47
5
votes
1 answer

How can I call MySQL stored procedure in ecto(=> 0.11)?

I am looking for a way to use call stored procedure, there was no found. Is it possible in an elixir's ecto lib?
aposto
  • 566
  • 5
  • 14
5
votes
2 answers

Is there an Elixir equivalent for Clojure's (source fn-name)?

Clojure has this handy way to view a function's definition in REPL. Is there one in Elixir REPL ?
Shanthakumar
  • 757
  • 6
  • 23
5
votes
1 answer

How to Display a single backslash in Elixir string

Can somebody tell me how to add a single backslash in the SQL statement in Elixir iex(1)> sql = "select * from user limit 1 \G;" "select * from user limit 1 G;" iex(2)> sql = "select * from user limit 1 \\G;" "select * from user limit 1 \\G;" I…
王志軍
  • 1,021
  • 1
  • 11
  • 21
5
votes
1 answer

Elixir tight-loop speed up

I'm looking for ways to speed up the "tight-loop" in my elixir program. Enum.reduce( list, 0, fn ({c,v},acc) -> v*elem(tuple_array,c) + acc end ) It's simply running through a list of tuples and for each it's doing: a tuple lookup (c is an…
GavinBrelstaff
  • 3,016
  • 2
  • 21
  • 39
5
votes
2 answers

Why does Elixir allow closures with undefined variables?

I can understand this: iex(7)> outside_val = 5 5 iex(8)> print = fn() -> IO.puts(outside_val) end #Function<20.90072148/0 in :erl_eval.expr/5> iex(9)> print.() 5 :ok What I don't get so much is why is it Elixir allows the print function to be…
Muhammad Lukman Low
  • 8,177
  • 11
  • 44
  • 54
5
votes
1 answer

How to type cast decode JSON as if it came from the database

When loading date/time types from the database, Ecto will cast to a Ecto.DateTime type. How can the same type casting be applied when loading a model from a JSON string defmodule Rocket.User do use Rocket.Model schema "users" do field…
Krut
  • 4,112
  • 3
  • 34
  • 42
5
votes
2 answers

Queue of worker processes in Phoenix application

I need something like PubSub but instead of broadcasting to all subscribers, the message is sent to only 1 subscriber (preferable the subscriber is chosen automatically based on the number of messages in it's receive buffer, lower is better). What…
Krut
  • 4,112
  • 3
  • 34
  • 42
5
votes
2 answers

What does "for" in "defimpl" in Elixir actually checks for?

Does "for" always checks the type of first argument in each function defined in a protocol? EDIT (rephrasing): When protocol method has only one argument, implementation is found based on the type of this single argument (either direct or as Any).…
5
votes
2 answers

Query Repo Using a String

I am using Phoenix with Ecto to query a database for a single record by the primary key. All of the documentation/examples show the usage as in a Phoenix Controller: def show(conn, %{"id" => id}) do m = Repo.get(MyModel, id) ... end However,…
Kombo
  • 2,371
  • 3
  • 34
  • 64
5
votes
2 answers

Is Stream.resource only from, not to?

Reading through the documentation, Stream.resource seems only intended for creating a resource that one can read/get values from, not write/put to. Have I understood correctly or am I reading it wrong? And if I've understand it correctly, what type…
stoft
  • 1,265
  • 8
  • 21
5
votes
1 answer

Change backend/module at deploy time in Elixir?

How would one go about implementing a replaceable backend (or basically any part or module) so that it can be replaced at configuration/deploy time in Elixir? My specific situation is a simple web app (in this case using Phoenix but I'm guessing…
stoft
  • 1,265
  • 8
  • 21