Skip to content

Instantly share code, notes, and snippets.

View programisti's full-sized avatar

Zaali Kavelashvili programisti

  • Tbilisi, Georgia
View GitHub Profile
@theevangelista
theevangelista / .formatter.exs
Created June 11, 2018 05:22
Elixir formatter for Phoenix without parentheses
[
  inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],
  locals_without_parens: [
# Kernel
    inspect: 1,
let scrollstep = 100
set smoothscroll
let scrollduration = 200
@timruffles
timruffles / dyanmic_or_di_elixir.md
Last active June 11, 2020 04:23
Approaches to dependency-injection/dynamic dispatch in elixir

In many production systems you'll want to have one module capable of talking to many potential implementations of a collaborator module (e.g a in memory cache, a redis-based cache etc). While testing it's useful to control which module the module under test is talking to.

Here are the approaches I can see. The two points that seem to divide the approaches are their tool-ability (dialyzer) and their ability to handle stateful implementations (which need a pid).

Passing modules

Modules are first class, so you can pass them in. Used in EEx, where passed module must implement a behaviour.