Skip to content

Instantly share code, notes, and snippets.

@Seberius
Last active August 29, 2015 14:09
Show Gist options
  • Save Seberius/3716a84fda8529890dd8 to your computer and use it in GitHub Desktop.
Save Seberius/3716a84fda8529890dd8 to your computer and use it in GitHub Desktop.
ClojureScript Factory Pattern Example
(definterface IBigInt
(add this y)
(subtract this y)
(multiply this y)
(divide this y))
(defprotocol BigInt [signum magnitude]
IBigInt
(add (add this y))
(subtract (sub this y))
(multiply (mul this y))
(divide (div this y)))
(defn big-int [num]
(if (= (typeof num) "String")
(BigInt (sig-from-str num) (mag-from-str num))
(BigInt (sig-from-num num) (mag-from-num num)f)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment