src/skinsuit/dispatch

Search:
Group by:
Source   Edit  

turns procs into case statements dispatched over single case branch fields of an object variant argument

Example:

import src/skinsuit/dispatch
type Foo = object
  case a: bool
  of false:
    x: int
  else:
    y: float

proc addStr(s: var seq[string], a: int) =
  s.add("int " & $a)
proc addStr(s: var seq[string], a: float) =
  s.add("float " & $a)
proc addStr(s: var seq[string], f: Foo) {.dispatchCase: f.}

var s: seq[string]
var f: Foo
addStr(s, f)
f = Foo(a: true, y: 1.2)
addStr(s, f)
f.y = 3.4
addStr(s, f)
f = Foo(a: false, x: 567)
addStr(s, f)
doAssert s == @["int 0", "float 1.2", "float 3.4", "int 567"]

Macros

macro dispatchCase(arg, prc)
Source   Edit  
macro dispatchCase(prc)
no specified argument to dispatch on, assumes the first argument Source   Edit