Welcome to ElixirDrops!

Hello there and welcome to the ultimate hub for the Elixir community! Whether you're a seasoned developer or just starting your journey, ElixirDrops is the perfect place to discover, share, and discuss the best tips and tricks for mastering Elixir. Sign in to explore, learn and become a contributor on this platform.

The Module Behind the Curtain

Use defdelegate when a function should simply forward its arguments to another module....
spapiernik

spapiernik

5 hours ago

0

Build strings with iodata, not concatenation

Building a string by repeatedly <>-ing onto an accumulator can be quadratic — but not for the reason most people think. The BEAM has a runtime optimiz...
almirsarajcic

almirsarajcic

22 hours ago

1

Ecto's :utc_datetime silently drops microseconds

:utc_datetime stores second precision. Hand it a DateTime.utc_now/0 value — which carries microseconds — and Ecto.Type.cast/2 truncates it with no war...
almirsarajcic

almirsarajcic

yesterday

0

get_in/2 needs Access.key!/1 for structs

get_in/2, put_in/3, and update_in/3 walk a path of atom keys through maps and keyword lists just fine — but the same atom path raises on a struct. ``...
almirsarajcic

almirsarajcic

2 days ago

2

Decimal `==` is not value equality

Decimal.new("1.0") and Decimal.new("1.00") represent the same number, but Elixir's == says they are different:...
almirsarajcic

almirsarajcic

3 days ago

0

`dbg/2` shows every step of your pipeline

Debugging a pipeline usually means breaking it apart with IO.inspect/2 calls between every stage, labelling each one so you can tell them apart, then ...
almirsarajcic

almirsarajcic

5 days ago

0

Stop blocking your supervisor in `init/1`

Every millisecond spent in init/1 is a millisecond your entire supervision tree is frozen. start_link/1 does not return until init/1 does, and the sup...
almirsarajcic

almirsarajcic

8 days ago

0

Name dynamic processes with `:via` tuples

The moment you need one process per game, per room, or per upload, the naming problem shows up — and the tempting fix is String.to_atom("game_#{id}")....
almirsarajcic

almirsarajcic

9 days ago

0

`attr` turns component bugs into compile errors

A function component is just a function taking assigns, which means a typo'd or forgotten assign fails the way any missing map key fails: at render ti...
almirsarajcic

almirsarajcic

10 days ago

0

`Ecto.Enum` maps atoms to integer columns

Status columns tend to rot the same way everywhere: an integer in the database, a string in the params, an atom in the business logic, and String.to_a...
almirsarajcic

almirsarajcic

11 days ago

0

Sub-binaries keep the whole payload in memory

Slicing a binary in Elixir does not copy it. binary_part/3 on a 1 MB payload hands you 100 bytes that quietly reference all 1 MB — and the parent cann...
almirsarajcic

almirsarajcic

12 days ago

0

Keep related writes together with `prepare_changes/2`

If a database write belongs to a changeset operation, prepare_changes/2 can run it in the same transaction. A common example is updating a counter whe...
almirsarajcic

almirsarajcic

13 days ago

0

Download/Read Hex Library Doc Offline

You can use mix hex.docs fetch ash to download documentation and read them offline with mix hex.docs offline ash. Whats more amazing is that in your ...
mnkhod

mnkhod

14 days ago

0

Give background processes useful labels

PIDs are not much help when several copies of the same worker are running. Process.set_label/1 adds a term that identifies what each process is doing....
almirsarajcic

almirsarajcic

15 days ago

0

Build an Ecto select a field at a time

An Ecto query has one select, which can make optional query helpers awkward. select_merge/3 lets each helper add fields to an existing map select. ``...
almirsarajcic

almirsarajcic

16 days ago

0