v = if (t = something1()), do: do_something1(v, t), else: v
v = if (t = something2()), do: do_something2(v, t), else: v
v = if (t = something3()), do: do_something3(v, t), else: v
?
Можно написать функцию и делать pipe def maybe_apply(value, nil, _applier), do: value def maybe_apply(value, fn, applier) when function(fn, 0), do: maybe_apply (value, fn.(), applier) def maybe_apply(value, check, applier) when not is_function(check) and is_function(applier, 2), do: applier.(value, check) q = (from v in Something, …) |> maybe_apply(opts[:limit] || @default_limit), &from(&1, limit: &2)) |> maybe_apply(opts[:begin_at], &from(t in &1, where: t.at >= ^&2)) |> maybe_apply(opts[:end_at], &from(t in &1, where: t.at < ^&2))
Обсуждают сегодня