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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
58 views

One-to-many and one-to-one in Elixir Ecto at the same time

I have 2 tables/schemas with relationship one-to-many, let's assume there is a Person that can have multiple Animal. Then each animal has person foreign key to implement this relationship. I use ...
1 vote
4 answers
69 views

Why there is no match error when matching Maps in Elixir

I am learning Elixir from offical docs. I am bit confused about my comprehension of Elixir's pattern matching. Please have a look at below example. [_] = [1,2,3] gives (MatchError) no match of right ...
3 votes
4 answers
2k views

Fibonacci with memoization elixir

I'm studying about functional programming and I made a simple fibonacci in elixir. I know that isn't possible change values in functional programming and I made a code to make fibonacci with ...
0 votes
1 answer
38 views

Inspecting BitString Data type in elixir interactive shell doesn't show info

Querying i("my string") returned data type of BitString Running h(BitString) command in iex returns Could not load module BitString, got: nofile. Compared to other data types that return ...
81 votes
7 answers
25k views

How do I raise a number to a power in Elixir?

How can I calculate a number with an exponent in Elixir? For example, 23 would return 8.
1 vote
1 answer
227 views

Elixir Ecto SQL comments /* comment /* Select 1;

Using Ecto.Query I'd like to be able to run a query and prepend a comment like this in Postges: /* my comment /* SELECT a.col FROM table a; I've tried "where: fragment", but it's not working ...
0 votes
1 answer
17 views

Uploaded images not showing on production Heroku

I have my Phoenix LiveView App deployed to Heroku. On the app, a user can upload their profile picture and it's saved on the uploads folder. The profile picture does not render on production but shows ...
1 vote
1 answer
66 views

Unable to receive TCP packets using erlangs `:socket` module

I am attempting to receive all TCP packets using low-level sockets via erlangs :socket module: def start() do {:ok, socket} = :socket.open(:inet, :raw, :tcp) recv(socket) end defp recv(socket) do ...
0 votes
1 answer
46 views

Phoenix: How can I set a environment variable?

I have a URL that will change depending on if I'm in dev or prod in dev, it should be http:localhost:3000 in prod, it should be https://www.foobar.com Where would I set the value of this environment ...
5 votes
4 answers
998 views

List of all modules implementing a behaviour in elixir

What could be the shortest possible way to get a list of all the modules implementing a behaviour? e.g. defmodule X do @callback foo() end defmodule A do @behaviour X def foo() do "...
1 vote
2 answers
80 views

Why there is no "Match Error" in following code?

I am new to Elixir, learning from official website. Why is output equal to {2,1}? iex> x = 1 iex> {x, ^x} = {2, 1} {2, 1} Doesn't it give match error as x is matched to 2 in that 2nd equation ...
0 votes
4 answers
153 views

Elixir: Behaviour of Backspace in iex

I'm using Elixir 1.15.0 with Erlang/OTP 26 on Arch Linux. I haven't configured anything; I'm just using the default setup. When I type the following code in IEx: i <- [1, 2, 3], j <- [10, 20, 30]...
0 votes
0 answers
44 views

I get an error when using mix ecto.create for my first Elixir project

When I do mix ecto.create I get following error: could not compile dependency :mint, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix ...
0 votes
1 answer
87 views

How to do an lseek on an open file, and read N bytes?

I'd like to use Elixir to read a binary file that has a fixed-length header, and data structures within that are of determinable length. These files can be huge, and I really don't want to be forced ...
39 votes
3 answers
32k views

Elixir: How to test multiple values in case condition?

Is there a shorter way to write this: case testvalue do 200 -> true 404 -> true _ -> false end It returns true for 200 or 404 and false for everything else. It would be ...
0 votes
1 answer
32 views

In Elixir, how to fix a nested list

In Elixir, I have the following list: [ :juridical_person_document, [re_developments: [[properties: [[re_development: [:re_developer]]]]]], :legal_address ] And my desired output would be this: [ :...
7 votes
6 answers
7k views

Convert maps to struct

I am trying to convert maps to struct as follow: I have a map: iex(6)> user %{"basic_auth" => "Basic Ym1hOmphYnJhMTc=", "firstname" => "foo", "lastname" => "boo"} ...
0 votes
1 answer
38 views

Testing raw sql queries in elixir

I'm trying to unit test a raw sql query but not getting any results. My test does a number of inserts like: Repo.insert!(%Inquiry{<fields>}) My inquiries select part does truncating of a ...
0 votes
1 answer
44 views

** (KeyError) key not found in: nil

So, I've got this struct: defmodule Card do defstruct id: nil, result_numbers: [], owned_numbers: [] end For each instance of this, I calculate the total number of owned_numbers that are in ...
0 votes
2 answers
54 views

Simplifying nested map parsing

So I'm trying to parse this string into two lists of integers: 69 12 75 19 83 56 73 53 52 91 | 83 63 56 30 77 94 12 81 42 69 52 70 6 97 20 43 61 22 75 19 73 32 74 53 91 This works: [results_s, ...
0 votes
1 answer
117 views

How to populate UI from @form content

I am new to LiveView, Phoenix and Elixir, and I am struggling to populate the UI from the form content. Here's a simplified version of what I have in my code: I have defined a struct with some simple ...
1 vote
1 answer
1k views

Migration from numeric ID to UUID

I'm looking for any tips and suggestions when it comes to migrating from the numeric ID's to the UUID's in Ecto. I'm having a project with a high amount of relations and I can't simply drop db and ...
0 votes
3 answers
201 views

How do I return 3 characters either side of a null byte in Elixir?

If I have a string, for example, hello this isa<<0>>string., how do I return the three characters either side of the null byte, including the null byte, e.g., isa<<0>>str? I ...
0 votes
1 answer
59 views

How can i realise queue system in message broker on Elixir using genServer?

What methods i could use to create queues in Elixir using genServer? Main idea is to spawn create long running stream def handle_call({:create_queue, queue_name}, _from, state) do create_queue(...
0 votes
2 answers
72 views

HTTPoison request CaseClauseError: no case clause matching JSON payload

I hit the following CaseClauseError message attempting to make a request with HTTPoison: 20:13:10.697 [error] #PID<0.2628.0> running Api.Endpoint (connection #PID<0.2608.0>, stream id 2) ...
0 votes
1 answer
45 views

Child element get 0 width when dynamically changing start/end properties [closed]

I have a double range slider, similar to the one implemented here. Unlike that tutorial, I am using TailwindCSS and am writing the Elixir/Phoenix/LiveView code. I was able to translate most of the ...
0 votes
3 answers
636 views

How to remove everything after a character in a string

I am getting a variable that holds a string. I want to trim it to first "?" sign, so I can pass it futher. For example, I want to always transfrom x = /example?idontwantthis to x = /example?
123 votes
9 answers
114k views

Convert Elixir string to integer or float

I need to convert a string to a floating point value or an integer. There was no method such as, string_to_integer
0 votes
0 answers
31 views

Elixir phoenix inputs_for does not preserve source

I'm currently working on a form to allow adding/changing and removing users from a device. This is a live view and deleting sets the action on the changeset to :delete which is used later when saving. ...
0 votes
2 answers
60 views

Elixir Explorer Equivalent to pandas fillna

I'm translating a pandas script to Elixir using Explorer.DataFrame. I found Explorer.Series.fill_missing/2, which will handle a single column. Is there a recommended way to mirror pandas' fillna such ...
0 votes
1 answer
37 views

MSO remove extra space before & after text

I am trying to create a button with the text "confirm your email now" and it will redirect to google website. I was able to get everything right but the width seems to be an issue as I am ...
0 votes
1 answer
38 views

Supervision strategy of a separately started process

Consider the following module-based Supervisor: defmodule MyApp.Supervisor do use Supervisor def start_link(init_arg) do Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__) end ...
0 votes
1 answer
70 views

phoenix heex does not see a variable in a loop

I'm new to Elixir and Phoenix, and I expect to get stuck, but this really surprises me. I'm fighting with the heex templating system. This is the part that I'm stuck at now: <div id="issues&...
1 vote
1 answer
41 views

Javascript not working as expected when show/ hide

I am trying to render a list of goals saved on the database on an index page, and to create a unique id for the divs, I added the goal_id to the id, like this: <%= for goal <- @goals do %>...
0 votes
0 answers
720 views

How to seed data in Elixir Phoenix

I generated a basic Phoenix API app. mix phx.new app I created a postgres database: app_dev I generated the following database Schema: mix phx.gen.json Items Item items name:string Now, I want to ...
0 votes
1 answer
47 views

Erlang/OTP ElixirLS version conflict

According to chatGPT ElixirLS version 0.17.10 is not compatible with Erlang/OTP 25.3.2.7 which is the package used to compile Elixir 1.15.7 with. Does anyone out there know what ElixirLS version ...
35 votes
3 answers
16k views

What does "|>" mean in elixir?

I'm reading through some code elixir code on github and I see |> being used often. It does not appear in the list of operation on the documentation site. What does it mean? i.e. expires_at: ...
2 votes
0 answers
979 views

Elixir Leader Election?

I am building a project in which I need a way to elect a leader between a group of processes. When the leader fails, a new leader must be elected. This must support processes which are in different ...
0 votes
3 answers
151 views

Instead of returning a list i get nil as a return type

I am new to elixir and functional programming as whole. I was starting out with super basic functions until i found a problem I couldnt find on the internet. I have the following module defmodule ...
0 votes
1 answer
65 views

How to read an external file from elixir script (exs)?

I'm writing an exs file that renders liveview. Is it possible to read javascript from an external javascript file using a script tag like below ? I'm getting this error. <script type="text/...
1 vote
2 answers
853 views

ETS table - Updating maps as records

Sample code: defmodule Foo do def fast_cars_cache do fast_cars = { %{color: "Red", make: "Mclaren", mileage: 15641.469}, %{color: "Blue", make: "Ferrari", mileage: 120012.481},...
0 votes
6 answers
135 views

Using data from a supervised processes to start another

The documentation details the following: When the supervisor starts, it traverses all child specifications and then starts each child in the order they are defined. This is done by calling the ...
0 votes
1 answer
84 views

Is it safe to use Task.start() inside of a Task.async_stream()?

I'm learning the Elixir Task module. https://hexdocs.pm/elixir/1.12/Task.html Is it safe to use Task.start() inside of a Task.asyn_stream()? Will this cause a process leak?
6 votes
2 answers
479 views

Use an OS process like a bash pipe: Send it STDIN and get its STDOUT

I'm trying to use an external process which reads the STDIN, and writes to STDOUT. I want to write the equivalent of this in Elixir, without using an external library or wrapper script: $ echo foo | ...
7 votes
2 answers
2k views

brew link error libpng and libtiff

I tried installing elixir using homebrew and I got the following errors ==> Pouring libtiff-4.0.3.yosemite.bottle.tar.gz Error: An unexpected error occurred during the `brew link` step The formula ...
9 votes
3 answers
6k views

Elixir: best practice to extract data from nested structs

In Elixir we can get data from nested data structures using data = %{field: %{other_field: 1}} data[:field][:other_field] If it contains lists it also can be done using data = %{field: %{...
0 votes
1 answer
78 views

How to call handle_event with params without using a form?

How do I call handle_event wish specific params without using a form? I'd like table row details to be displayed in a modal when row_click happens. I am able to trigger handle events, but params are ...
1 vote
3 answers
73 views

Elixir count number of occurences when condition is satisfied

I try to do the following thing in Elixir that can be achieved in Python: sum = 0 for elem in list: if elem >= 5: sum += 1 For example: I want to return the number 3 given the list [0, 5, 8, ...
5 votes
3 answers
2k views

Phoenix dynamic classnames Phoenix.HTML

I would like to join a dynamic classname name with a static one. <div class=<%="#{getClass(app.status)} two" %> This results in <div class="one" two> Instead of &...
0 votes
2 answers
89 views

Adding a Limit Option to Ecto's Repo.preload in Elixir

I have a function in Elixir using Ecto that preloads associations for a given entity. The current implementation looks like this: @spec get(integer() | String.t(), list()) :: t() | nil def get(id, ...

1
2 3 4 5
191