Skip to content
/ variant Public
forked from yglukhov/variant

Variant type and type matching for Nim

License

Notifications You must be signed in to change notification settings

boyanl/variant

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

variant Build Status nimble

Variant type and type matching for Nim

import variant

var v = newVariant(5)
assert v.ofType(int)
assert v.get(int) == 5

v = newVariant(3.0)
assert v.ofType(float)
assert v.get(float) == 3.0

v = newVariant(@[1, 2, 3])
assert v.ofType(seq[int])
assert v.get(seq[int])[1] == 2

Matching:

var v = newVariant(@[1, 2, 3])
assert v.ofType(seq[int])
variantMatch case v as u
of int:
    echo "u is int: ", u
of seq[int]:
    echo "u is seq[int]: ", u
else:
    echo "dont know what v is"

Will output:

u is seq[int]: @[1, 2, 3]

About

Variant type and type matching for Nim

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Nim 100.0%