Replaced implementations to use foldRight.
Replaced foldRight with /: operator, because Scala can look worse than Perl