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.

Capture warnings with Code.with_diagnostics/2

Use Code.with_diagnostics/2 when warnings and errors need to become structured data instead of terminal text....
almirsarajcic

almirsarajcic

5 hours ago

0

Update matching list items with Access.filter/1

Use Access.filter/1 to update only the list elements that match a predicate, without mapping and rebuilding the surrounding structure yourself....
almirsarajcic

almirsarajcic

yesterday

0

Discard late replies with process aliases

Send hand-rolled request replies to a process alias, then deactivate the alias when the caller stops waiting....
almirsarajcic

almirsarajcic

2 days ago

0

Reject unknown struct keys with struct!/2

Use struct!/2 when runtime attributes must contain only fields that belong to the struct....
almirsarajcic

almirsarajcic

3 days ago

0

The Module Behind the Curtain

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

spapiernik

3 days ago

1

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

4 days ago

2

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

5 days ago

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

6 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

6 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

8 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

12 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

13 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

14 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

14 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

15 days ago

0