(#11331) Add support to end a lambda with = expression.

This relaxes the constraint that a = expr must be the only statement
in a lambda (or be a sequence of statements). Is is now instead possible
to place this statement last after a sequence of statements.

This commit also fixes an issue where the last value of the lambda and
foreach function did not produce a value.