sweetener v0.1.0 Sweetener
Sweetener is a set of nifty functions I missed in Elixir core.
Link to this section Summary
Functions
An implementation of ruby’s tap
method. Inside the block the tapped value
is accessible with _()
function
Link to this section Functions
An implementation of ruby’s tap
method. Inside the block the tapped value
is accessible with _()
function.
For convenience, {:ok, value}
is tapped as value
itself,
everything else is tapped as is.
tapped = tap {:ok, 42} do
42 = _()
:error
end
assert tapped == {:ok, 42}
It’s useful for more concise logging etc. without intermediate local variables:
use Sweetener
tap Supervisor.start_link(children, opts) do
IO.inspect Supervisor.count_children(_())
#=> %{active: 1, specs: 1, supervisors: 0, workers: 1}
end #=> returning {:ok, pid} tuple