Preheat your oven to 350°F (175°C).
Cook the elbow macaroni according to the package instructions, then drain and set aside.
In a large saucepan, melt the butter over medium heat.
Whisk in the flour to make a roux, cooking for about two minutes until it turns golden.
Gradually add the half-and-half and whole milk while continuously whisking to avoid lumps.
Bring the mixture to a low boil, then reduce the heat and simmer, stirring frequently, until thickened (about 10 minutes).
Remove the saucepan from heat and whisk in the cheddar, Gruyere, mascarpone cheese, and the egg until smooth and creamy.
Combine the cooked macaroni with the cheese sauce, ensuring each piece is well-coated.
If using, mix in the diced ham and hot sauce for an extra kick of flavor.
Pour the mac and cheese into a baking dish.
Sprinkle with salt, pepper, and rosemary.
Bake in the preheated oven for about 20 minutes, or until bubbly and golden on top.