v2 / vlib / v / tests / generics / generic_if_ret_test.v
8 lines · 7 sloc · 159 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn clamp[T](a T, x T, b T) T {
2 min := if x < b { x } else { b }
3 return if min < a { a } else { min }
4}
5
6fn test_main() {
7 assert dump(clamp(1, 2, 3)) == 2
8}
9