A switch type function

Less verbose (and builtin) is chained ternaries. With indentation they can be quite readable for short expressions like these:

n = 1.0
m =       n ≤ 0.1 ? 0.0 :
    0.1 < n ≤ 0.6 ? 1.0 :
    0.6 < n ≤ 0.8 ? 1.1 :
    0.8 < n ≤ 1.0 ? 1.2 :
    1.0 < n ≤ 1.3 ? 1.35 :
    #= otherwise =# 2.2
17 Likes