Why can’t I chain String.replace?

EDIT On the master branch of Elixir, the compiler will warn if a function is piped into without parentheses if there are arguments. This is an issue of precedence that can be fixed with explicit brackets: price |> to_string |> String.replace(“.”, “,”) |> String.replace(~r/,(\d)$/, “,\\1 0″) |> String.replace(” “, “”) Because function calls have a … Read more

Erlang Processes vs Java Threads

Repeat after me: “These are different paradigms” Say that aloud 20 times or so — it is our mantra for the moment. If we really must compare apples and oranges, let’s at least consider where the common aspects of “being fruit” intersect. Java “objects” are a Java programmer’s basic unit of computation. That is, an … Read more

How can I schedule code to run every few hours in Elixir or Phoenix framework?

There is a simple alternative that does not require any external dependencies: defmodule MyApp.Periodically do use GenServer def start_link(_opts) do GenServer.start_link(__MODULE__, %{}) end def init(state) do schedule_work() # Schedule work to be performed at some point {:ok, state} end def handle_info(:work, state) do # Do the work you desire here schedule_work() # Reschedule once more … Read more

Are Elixir variables really immutable?

Don’t think of “variables” in Elixir as variables in imperative languages, “spaces for values”. Rather look at them as “labels for values”. Maybe you would better understand it when you look at how variables (“labels”) work in Erlang. Whenever you bind a “label” to a value, it remains bound to it forever (scope rules apply … Read more

Elixir lists interpreted as char lists

Elixir has two kinds of strings: binaries (double quoted) and character lists (single quoted). The latter variant is inherited from Erlang and is internally represented as a list of integers, which map to the codepoints of the string. When you use functions like inspect and IO.inspect, Elixir tries to be smart and format a list … Read more

Elixir Coin Change [closed]

try this defmodule MejorCambio do def darcambio(abono, adeudo) do td = abono – adeudo IO.inspect(“Tu cambio es de #{td}”) Enum.reduce([200,100,50,20,10, 5, 2, 1], %{abono: abono, adeudo: adeudo} , fn divisa, acc -> cambio = acc.abono – acc.adeudo repeat = div(cambio, divisa) acc2 = rem(cambio, divisa) %{deno: divisa , val: repeat} |> IO.inspect() %{acc | adeudo: … Read more

How can I remove elixir completly from Mac [closed]

You may want to install Elixir using Homebrew: brew install elixir In case you need to get aquatinted with Homebrew, visit the https://brew.sh. There, you’ll see the installation instruction, e.g.: /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Spanning repeatable keys

1> L_tup = [ 1> {“Caerus1”, “Ramses Refiner”}, 1> {“Caerus1”, “Jupiter Refiner”}, 1> {“Caerus1”, “Jupiter Other”}, 1> {“Caerus1”, “Trader 13”}, 1> {“Caerus1”, “Cathode Supplier 4”}, 1> {“Dionysus3”, “Cathode Supplier 4”}, 1> {“Dionysus3”, “Ramses Refiner”}, 1> {“Dionysus3”, “Trader 13”}, 1> {“Dionysus3”, “Jupiter Refiner”}, 1> {“Dionysus3”, “Jupiter Other”}, 1> {“Prometheus2”, “Jupiter Other”}, 1> {“Prometheus2”, “Ramses Refiner”}, 1> … Read more