Open In App

Julia – MapReduce

The map() and reduce() are the higher-order functions that are found in almost every programming language. The mapreduce() can be used to perform the task of an individual map() and reduce() together.

Syntax:



mapreduce(f, op, itr)

Like “mapreduce(f, op, v0, itr)”, this cannot be used with empty collections.



Example 1: Below is the Julia program to implement mapreduce:




mapreduce(x->x^x, +, [1,2,3])

Output:

 

Example 2: Below is the Julia program to implement mapreduce:




mapreduce(x->-x, *, [8, 9, 10])

Output:

 

Article Tags :