Use power of Generics to infer types

in more functions
Merge pull request #2216 from omidkrad/master

Use power of Generics to infer types in more functions