Skip to content

Instantly share code, notes, and snippets.

@hamidb80
Created August 11, 2025 02:05
Show Gist options
  • Save hamidb80/960d78b120e88174cd4691350182d914 to your computer and use it in GitHub Desktop.
Save hamidb80/960d78b120e88174cd4691350182d914 to your computer and use it in GitHub Desktop.
static modulation for nim
import std/random
func mods[T: static Natural](a: int, b: type T): range[0 .. T-1] =
cast[type result](a mod b.int)
let n = rand 0 .. 100
case n.mods 4
of 3,2,1: echo "huh"
of 0 : echo "got you"
@hamidb80
Copy link
Author

the compiler does not nag and say:

not all cases are covered for the expression n.mods 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment