LevelQ[expr]LevelQ[2]
LevelQ[{2, 4}]
LevelQ[Infinity]
LevelQ[a + b]
We will define MyMap with the “level” parameter as a synonym for the Builtin Map equivalent:
MyMap[f_, expr_, Pattern[levelspec, _?LevelQ]] := Map[f, expr, levelspec]
MyMap[f, {{a, b}, {c, d}}, {2}]
Map[f, {{a, b}, {c, d}}, {2}]
But notice that when we pass an invalid level specification, MyMap does not match and therefore does not pass the arguments through to Map. So we do not see the error message that Map would normally produce
Map[f, {{a, b}, {c, d}}, x]
MyMap[f, {{a, b}, {c, d}}, {1, 2, 3}]