You can send the type as an argument, either as a generic or as a `typedesc`
parameter:
let x = 3
proc by_two(val: int, T: typedesc[int]): int =
result = val * 2
proc by_two(val: int, T: typedesc[string]): string =
result = $val & " and " & $val
let a = x.by_two(int)
let b = x.by_two(string)
echo a
echo b
proc by_two[T: int|string](val: int): T =
when T is int:
result = val * 2
elif T is string:
result = $val & " and " & $val
let c = x.by_two[:int]()
let d = x.by_two[:string]()
echo a
echo b
- clarification: overloading is strictly on parameter types? JohnAD
- Re: clarification: overloading is strictly on parameter types? GULPF
