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

Fragments reuse

Is it somehow possible to reuse fragments? In an example like this def unpublished_by_title(title) do from p in Post, where: is_nil(p.published_at) and fragment("downcase(?)", p.title) == ^title end It seems like it would be very…
ave
  • 18,083
  • 9
  • 30
  • 39
5
votes
1 answer

Shared code in umbrella app

I have the following directory structure for my umbrella app : umbrella_app/ _build/ apps/ client/ config/ lib/ client.ex test/ server/ ... config/ Is there a way I can write…
Kernael
  • 3,270
  • 4
  • 22
  • 42
5
votes
2 answers

assign @changeset not available in eex template

I am trying to learn the Phoenix's Form system with including the Ecto.Model's but i have encountered a problem that i can't pass. I have created a form:
<%= form_for @changeset, user_path(@conn, :create), fn f -> %> …
Haito
  • 2,039
  • 1
  • 24
  • 35
5
votes
1 answer

Is there a way to explicitly write a elixir function to be tail call optimised?

In Clojure for example you can use the recur especial form to explicit the intention to use non-stack-consuming recursive calls, and is verified by the compiler. As it's wrote in the Clojure docs: "recur in other than a tail position is an error",…
sanrodari
  • 1,602
  • 2
  • 13
  • 23
5
votes
2 answers

elixir delete many to many association

I have two models: User and Group. They are many to many associated through a join table. When I try to delete a user ( or a group), it raises this error: ** (Ecto.ConstraintError) constraint error when attempting to delete model: * foreign_key:…
user3546621
  • 357
  • 3
  • 12
5
votes
1 answer

How does recursion work in Elixir

Simple function in Elixir, returning a list of numbers from to: defmodule MyList do def span(_), do: raise "Should be 2 args" def span(from, to) when from > to, do: [ to | span(to + 1, from) ] def span(from, to) when from < to, do: [ from |…
Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
5
votes
2 answers

store variables in a module

I thought this would be a very basic question, but after searching the net, I couldn't find a solution. I'd like to store a variable somewhere and refer to it later in a function. The problem I'd like to solve is the following: I do a HTTP Request…
0xAffe
  • 1,156
  • 1
  • 13
  • 29
5
votes
1 answer

How to show all records of a model in Phoenix select field

I have following models... Page Category i have following code in new action of page_controller.ex def new(conn, _params) do changeset = Page.changeset(%Page{}) categories = Repo.all(Category) render(conn, "new.html", changeset: changeset,…
Murtza
  • 1,386
  • 1
  • 19
  • 27
5
votes
2 answers

Ecto: Casting %Plug.Upload to virtual field for file upload validations

I would like to be able to trigger a file upload only when a changeset is valid and contains a file. Is it possible/A good idea to cast a %Plug.Upload e.g def changeset(model, params \\ :empty) do model |> cast(params, @required_fields,…
Aaron Dufall
  • 1,177
  • 10
  • 34
5
votes
2 answers

Elixir reduce order of elements

Trying to understand how Elixir does Enum.reduce, I plugged it into a puts to watch the ouput. I'm not clear on why it executes the second list element first, instead of the first, and then steps through all of the others independently. iex (30)>…
Rick R
  • 173
  • 6
5
votes
2 answers

Construct a random string of n length from a list using Elixir

I have a list of strings that I want to use construct a new string of n length. How would I go about randomly selecting an elements from the list, and appending them to the string until I've reached the desired length? parts = ["hello", "world",…
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263
5
votes
3 answers

Cannot connect Elixir nodes on MacBook Pro

I can’t seem to connect two nodes on my macbook pro. I am using iex —sname foo and iex —sname bar in two separate terminal sessions and they can’t see each other. I’ve tried setting the firewall and turning it off completely with no luck. From foo,…
ewH
  • 2,553
  • 2
  • 20
  • 13
5
votes
2 answers

How to test a multi database Elixir (Phoenix, Ecto) app

What is the correct way of running tests that access multiple databases? I'm writing a tiny API which has to access multiple databases. I defined 2 Repos each wrapping a different database: # config/dev.exs, config/test.exs, ... config :my_app,…
5
votes
1 answer

Postgres health check in Elixir

I am trying to do a simple health check on my postgres database for elixir. In rails I would do something like: ActiveRecord::Base.verify_active_connections Is there anything similar on elixir?
Gary
  • 443
  • 9
  • 22
5
votes
1 answer

Elixir type specs and parameterized type variables

I am trying to figure out how to combine parameterized types and type variables in Elixir type and function specs. As a simple example, let's say I am defining a Stack module: defmodule Stack do @type t :: t(any) @type t(value) :: list(value) …
Jason Voegele
  • 1,918
  • 1
  • 19
  • 18