A micro-gem DSL for compound conditionals.
Allowable lets you decompose large/long conditional chains into readable, testable, and inspectable segments with Ruby blocks.
A micro-gem DSL for compound conditionals.
Allowable lets you decompose large/long conditional chains into readable, testable, and inspectable segments with Ruby blocks.
;; This is at: https://gist.github.com/8655399 | |
;; So we want a rhyming dictionary in Clojure. Jack Rusher put up | |
;; this code here: | |
;; | |
;; https://gist.github.com/jackrusher/8640437 | |
;; | |
;; I'm going to study this code and learn as I go. | |
;; | |
;; First I put it in a namespace. |
defmodule MyApp.Periodically do | |
use GenServer | |
def start_link do | |
GenServer.start_link(__MODULE__, %{}) | |
end | |
def init(state) do | |
Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours | |
{:ok, state} |
# `Hash#dig!` | |
# | |
# Like Ruby 2.3's `Hash#dig`, but raises an exception instead of returning `nil` | |
# when a key isn't found. | |
# | |
# Ruby 2.3 introduces the new Hash#dig method for safe extraction of | |
# a nested value. See http://ruby-doc.org/core-2.3.0/Hash.html#method-i-dig. | |
# It is the equivalent of a safely repeated Hash#[]. | |
# | |
# `#dig!`, on the other hand, is the equivalent of a repeated `Hash#fetch`. It's |
Since a local variable head
is defined in the quoted expression, the recursive call to the function overwrites the value of head
in the expanded expression. This isn't a problem when quoting in the tail of the list , because head
was already used to build as its head. :mindblown:
Here's the final implementation of recurse/1:
def recurse([h|t]) do
t = recurse(t)
quote do
defmodule DateTimeGenerators do | |
use ExUnitProperties | |
@time_zones ["Etc/UTC"] | |
def date do | |
gen all year <- integer(1970..2050), | |
month <- integer(1..12), | |
day <- integer(1..31), | |
match?({:ok, _}, Date.from_erl({year, month, day})) do |