Processing a Sequence of Heterogeneous Items

… With variant objects

code.nim

in.yaml

importyaml,streamstypePerson=objectname:stringContainerKind=enumckString,ckInt,ckBool,ckPerson,ckNoneContainer=objectcasekind:ContainerKindofckString:strVal:stringofckInt:intVal:intofckBool:boolVal:boolofckPerson:personVal:PersonofckNone:discardsetTagUri(Person,nimTag("demo:Person"))# tell NimYAML to use Container as implicit type.# only possible with variant object types where# each branch contains at most one object.markAsImplicit(Container)varlist:seq[Container]vars=newFileStream("in.yaml")load(s,list)s.close()assert(list[0].kind==ckString)assert(list[0].strVal=="this is a string")# and so on