The second way ("is not so neat") is the canonical way of doing it. This is called a capture helper. It takes advantage of capture to be able to introduce a "local" type variable. The helper method is usually made private
so that outside code doesn't have to know it's there.
P.S. S
is not used anywhere