Following code gives me warning at compile time:
Warning: use of operator ‘>’ has no effect
rd(a,{x,y}),
List = [#a{x=1,y=2}, #a{x=3,y=4}],
lists:filter(
fun(E) ->
E#a.x > 1, E#a.y =:= 2
end, List).
But when I substitute comma with andalso, there is no warning.
Using comma in this case only separates two actions, without effect to each other:
E#a.x > 1and the next operation (which is result of function)E#a.y =:= 2It means that in your case, filter function is equal to:
Only if you’re writing guard expressions usage of comma is equal to usage of
andalso, otherwise – comma just a separator between actions.So, you may rewrite your function in two ways:
1)
2)