scala: ideomatic and optimized versions