typely
Version:
Lightweight (meaning relatively fast) type-checking in CoffeeScript.
36 lines (28 loc) • 787 B
text/coffeescript
{type} = require "fairmont"
$ = module.exports
class Signature
constructor: ->
= {}
= => false
on: (types...,processor) ->
[types.join "."] = processor
@
fail: (handler) =>
= handler
@
match: (args) ->
types = (type arg for arg in args)
signature = types.join "."
processor = [signature]
if processor?
processor
else
console.log signature
console.log
$.overload = (declarator) ->
signature = new Signature
match = (types...,handler) -> signature.on types..., handler
fail = (handler) -> signature.fail handler
declarator( match, fail )
(args...) -> (signature.match( args )).call(this, args...)