Functional languages provide you with the ability to concisely define the intension of a program, without low-level issues getting in the way. This can be clearly seen when implementing the Quick sort algorithm. Often referred to as ‘partition-exchange’ sort, this divide and conquer algorithm recursively divides a list into two sub-lists, based on a chosen pivot element.
This description can be clearly expressed in the Scala implementation shown below.
So as to highlight the key points in this post, the example has been restricted to only sort lists of integers. As well as this, the leftmost element is chosen as the pivot, causing worst-case behavior on already sorted arrays.