I no longer get the point of this forum post and should no longer participate, 
but...Thank's to leorize's <https://github.com/alaviss/union> there is a usable 
union solution.
    
    
    import union
    type
      CodeCmd = distinct string
      ReplaceCmd = object
        elementId, content: string
      
      Command = union(CodeCmd | ReplaceCmd)
    
    proc eval(code: CodeCmd): lent string = string code
    proc eval(replace: ReplaceCmd): lent string = replace.content
    
    var c = CodeCmd"alert('hi')" as Command
    assert unpack(c, eval(it)) == "alert('hi')"
    c = ReplaceCmd(content: "meh") as Command
    assert unpack(c, eval(it)) == "meh"
    
    
    Run

Reply via email to