Last active
December 31, 2015 22:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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