Coconut is a variant of Python built for simple, elegant, Pythonic functional programming. Coconut syntax is a strict superset of Python 3 syntax. That means users familiar with Python will already be familiar with most of Coconut.
The Coconut compiler turns Coconut code into Python code. The primary method of accessing the Coconut compiler is through the Coconut command-line utility, which also features an interpreter for real-time compilation. In addition to the command-line utility, Coconut also supports the use of IPython / Jupyter notebooks.
While most of Coconut gets its inspiration simply from trying to make functional programming work in Python, additional inspiration came from Haskell, CoffeeScript, F#, and patterns.py.
def quick_sort(l): """Return a sorted iterator of l, using the quick sort algorithm, and without using any data until necessary.""" match [head] :: tail in l: tail, tail_ = tee(tail) yield from (quick_sort((x for x in tail if x <= head)) :: (head,) :: quick_sort((x for x in tail_ if x > head)) ) # :: - is lazy + for iterators # yield from - adds another whole iterator # tee - solves a problem for functional programming created by the implementation of Python’s # iterators: whenever an element of an iterator is accessed, it’s lost.