Clojure 如何使用plumatic模式来定义一个函数,该函数的参数可以是2种或更多不同的类型?

Clojure 如何使用plumatic模式来定义一个函数,该函数的参数可以是2种或更多不同的类型?,clojure,plumatic-schema,Clojure,Plumatic Schema,我不知道如何使用s/other或s/conditional作为输入列表的一部分。要执行以下操作: (s/defn parse-int :- s/Int [input :- ; either s/Int or s/Str] ; if s/Int input ; if s/Str (read-string input) )) 您也可以使用或,但它已被弃用。哦,很好,我不知道您可以在之后调用fn:-有一个。 (sc/defn parse-int :- sc/Str

我不知道如何使用s/other或s/conditional作为输入列表的一部分。要执行以下操作:

(s/defn parse-int :- s/Int
  [input :- ; either s/Int or s/Str]
    ; if s/Int
    input
    ; if s/Str
    (read-string input)
))

您也可以使用
,但它已被弃用。

哦,很好,我不知道您可以在
之后调用fn:-
有一个。
(sc/defn parse-int :- sc/Str
    [input :- (sc/cond-pre sc/Int sc/Str)]
    (if (string? input) "a string" "not a string"))

(parse-int 34545) ; "not a string"
(parse-int "34545") ; "a string"