I'm new to scala and I've stumbled upon some weird cases where type inference does not work as expected. for example, this does not compile:
List(1, 2, 3, 4, 5, 6)
.map(if _ > 3 then "foo" else "bar")
the compiler explicitly states it can't infer the type of _$1 which I take to be the first parameter of the function the syntax above desugars to.
somewhat frustratingly, the below code compiles just fine, even with no type annotation:
List(1, 2, 3, 4, 5, 6)
.map{ n => if n > 3 then "foo" else "bar"}
clearly there's something I'm not grasping about how _ desugars. can somebody clue me in on what's missing?