I've been a touch typist on the keyboard for a long time, and the reason is that I've internalized the shape of every word in my mind because I've typed the same words so many times throughout my life. For instance, the word "example" can be used in many different sentences, it's a popular word so it's second nature to type.
Similarly does some random combination of intervals that's a part of a melody be used in many songs again and again? for example "unison + descending major third + ascending major second + descending perfect fifth". So that when you hear them you can play them right away because you've done them so many times in other songs. So if I practice playing by ear enough songs in enough keys, then I'll know how to play any new song on the fly since it'll just be a new set of interval combinations I've already practiced? I'm pretty sure this is true for harmony, but I was wondering for melodies.