Athenos07
5/2/2018 - 8:21 AM

Functional Programming

(ns test-project.core)

(define my-mulsti class)

(defmethod my-mulsti java.lang.String [a]
  str "as string: " a)

(defmethod my-mulsti java.lang.Long [a]
  str "as long: " a)

(my-multi 1) ;; => as long: 1
(my-multi 1) ;; => as string: 1

;; ------------------------------------

(defmethod arity-dispatch
  (fn [& args]
    (count args)))
  
(defmethod arity-dispatch 1 [a]
  (str "arity 1: " a))

(defmethod arity-dispatch 2 [a, b]
  (str "arity 1: " a " " b))

(defmethod arity-dispatch :default [& rest]
  (str "arity *: " rest))