Change while to map and use lambda

Signed-off-by: dwSun <tonghuren@gmail.com>