Cartesian product of two or more lists: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a compact native approach (no imports), in a more mathematical idiom, demonstrating use of Python for functional programming)
m (→‎Using the 'Applicative' abstraction: (Minor edit in preamble - foreground link to Applicative Functor wiki page))
Line 2,107:
===Using the 'Applicative' abstraction===
 
This task calls for alternative approaches to defining cartesian products, and one particularly compact alternative route to a native cartesian product (in a more mathematically reasoned idiom of programming) is through the Applicative abstraction (see [[wp:Applicative_functor|Applicative Functor]]), which is slightly more general than the possibly better known '''monad''' structure. Applicative functions are provided off-the-shelf by languages like Agda, Idris, Haskell and Scala, and can usefully be implemented in any language, including Python, which supports higher-order functions.
 
If we write ourselves a re-usable Python '''ap''' function for the case of lists (applicative functions for other 'data containers' can also be written – this one applies a list of functions to a list of values):