Sorting in Scala, tails of Functional Programming (medium.com)