In a standing mixer bowl, whisk together the egg yolks and sugar until smooth and the mixture forms ‘ribbons’ as the whisk rotates.
Add the flour or cornstarch slowly, bit by bit, into the mixture until fully incorporated. The mixture should be a pale yellow and quite fluffy.
Meanwhile, heat the milk (or milk and cream) over moderate heat until hot but not boiling. You will see little bubbles just beginning to form around the edge of the pot. (If you are using a vanilla bean, add it to the milk and let it steep for a few minutes, then remove it.) Take the milk off the heat and whisk it, little by little, into the mixer bowl.
Now pour the whole mixture from the bowl into the pot (along with the vanilla extract if using) and place it over very gentle heat, whisking continuously and vigorously. After a while, it should begin to thicken. Keep stirring until you have a thick custard that pulls away from the bottom of the pot as you whisk.
Remove from the heat, stir in the grated lemon zest if using, and let the mixture cool. It will thicken further as it cools. If keeping for longer than 30 minutes or so, cover with film wrap to avoid a film forming on top.