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

how to use plumatic schema to define a function that takes an argument that can be 2 or more different types?

我不知道如何使用 s/either 或 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)
))
(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"

您也可以使用 either,但已弃用。