Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Clojure模式输入转换为小写。_Clojure - Fatal编程技术网

将Clojure模式输入转换为小写。

将Clojure模式输入转换为小写。,clojure,Clojure,我可以将clojure模式输入验证为字符串,如下所示 name :- s/Str, place :- s/Str, 如何为电子邮件编写defschema以便像这样使用 email : - s/Email 将其转换/强制为小写 我正好有一个 (ns myapp.utils.schema (:import [org.apache.commons.validator.routines EmailValidator]) (:require [clojure.string :as str]

我可以将clojure模式输入验证为字符串,如下所示

name :- s/Str, 
place :- s/Str,
如何为电子邮件编写defschema以便像这样使用

email : - s/Email 

将其转换/强制为小写

我正好有一个

(ns myapp.utils.schema
  (:import [org.apache.commons.validator.routines EmailValidator])
  (:require [clojure.string :as str]
            [schema.core :as s]
            [schema.coerce :as sco]))

(def valid-email? "Checks that the value is a valid email string."
  (let [ev (EmailValidator/getInstance)]
    (fn [s]
      (and
        (string? s)
        (.isValid ev, ^String s)
        ))))

(def Email "Email schema type, stricter than schema.core/Str."
  (s/pred valid-email?))

(defn sanitize-email [s]
  (if (string? s)
    (-> s str/lower-case str/trim)
    s))

(defn email-matcher [s]
  (when (= Email s) sanitize-email))


(def matcher
  "The Plumatic matcher used for Plumatic schema coercion in myapp."
  (sco/first-matcher [email-matcher,,,]))

(defn coercer 
  [schema]
  (sco/coercer schema matcher))

;; ...

(ns myapp.customer
  (:require [schema.core :as s]
            [myapp.utils.schema :as sc]))

(def Customer 
  {:customer/email sc/Email 
   :customer/name s/Str})

(def coerce-customer (sc/coercer Customer))

(coerce-customer {:customer/email "vAlENTin@gmaIl.com "
                  :customer/name "Valentin"})
=> {:customer/email "valentin@gmail.com"
    :customer/name "Valentin"}