Skip to content

Instantly share code, notes, and snippets.

@jlmferreira
Last active December 31, 2015 22:59
Show Gist options
  • Save jlmferreira/8057111 to your computer and use it in GitHub Desktop.
Save jlmferreira/8057111 to your computer and use it in GitHub Desktop.
Evitar que a função seja chamada sem ter passado por nenhum validador, gerando dado inconsistente.
(defn border [x]
(cond (= (meta x) nil) "nao autorizado"
(= ((meta x):type) "valinor") x
:default "lixo" ))
;Associar um meta a sua função de validação
;teste
(def x (with-meta [1 2 3 4] {:type "valinor"}))
(border x)
; => [1 2 3 4]
(border [1 2 3 4 5])
; => não autorizado
(def x (with-meta [1 2 3 4] {:type "outracoisa"}))
(border x)
; => lixo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment