Julia - MapReduce

Last Updated : 28 Apr, 2025

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:

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


Output:

Output_1
 

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

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


Output:

Output 2
 
Comment