Peter Kreeft said this quote

Saint Thomas Aquinas says, wisely, that the only way to drive out a bad passion is by a stronger good passion. The same is true of thoughts as of passions. When your mind wanders, like a child, your will must bring it back, like a mother. [. . .] The will-parent must discipline the mind-child, avoiding both the opposite extremes commonly made in disciplining either children or thoughts: tyranny or permissiveness.