# Mapreduce with multiple arguments

**URL:** <https://discourse.julialang.org/t/mapreduce-with-multiple-arguments/129158>\
**Category:** New to Julia\
**Tags:** time-series\
**Created:** [May 19, 2025, 8:58pm UTC](https://discourse.julialang.org/t/mapreduce-with-multiple-arguments/129158 "2025-05-19T20:58:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmacooper](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@emmacooper](https://discourse.julialang.org/u/emmacooper)\
**Post date:** [May 19, 2025, 8:58pm UTC](https://discourse.julialang.org/t/mapreduce-with-multiple-arguments/129158/1 "2025-05-19T20:58:46Z")

</div>

A similar question was asked in “Method of Mapreduce with multiple arguments” but my implementation of the solution offered in this post did not seem to work.

The problem: I have many `TimeArrays` (created using `TimeSeries.jl`) that I would like to use the `merge` function on. `merge` takes an optional argument called `method` that I need to set with a single `Symbol` (this relates to the index on which the `TimeArrays` are merged). How can I use `mapreduce` to merge many `TimeArrays` at once while including this optional parameters?

Here is some example code. I have only included three `TimeArrays` in the example, but in reality there are thousands, so it is not feasible to simply compose them by hand.

```using
idx1 = [j for j in DateTime(2000,3,1,9):Hour(1):DateTime(2000,3,1,17)]
idx2 = [j for j in DateTime(2000,3,1,8):Hour(1):DateTime(2000,3,1,16)]
idx3 = [j for j in DateTime(2000,3,1,7):Hour(1):DateTime(2000,3,1,15)]

data1 = rand(Normal(1, 0.5), length(idx1))
data2 = rand(Normal(1, 0.5), length(idx2))
data3 = rand(Normal(1, 0.5), length(idx3))

tas = [TimeArray(i, d) for (i, d) in zip([idx1, idx2, idx3], [data1, data2, data3])]

```

I can easily merge two of the `TimeArrays` using the optional parameter `method` with `merge(tas[1], tas[2], method=:outer)`and I can merge all three of the `TimeArrays` without the parameter `outer` using `reduce(merge, tas)`. However, I get a `MethodError` when I try

`mapreduce(x -> merge(x, method=:outer), tas)`

I tried to rewrite this based on the post referenced at the top as  
`mapreduce((x, y) -> merge(x, method=y), zip(tas, :outer))`  
but got another `MethodError`. Where am I going wrong?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 19, 2025, 9:04pm UTC](https://discourse.julialang.org/t/mapreduce-with-multiple-arguments/129158/2 "2025-05-19T21:04:02Z")

</div>

Welcome!

> [@emmacooper](#):
>
> `mapreduce((x, y) -> merge(x, method=y), zip(tas, :outer))`

You likely want:

```Julia
reduce((x, y) -> merge(x, y, method=:outer), tas)

```

---

<div class="post-metadata">

**Author:** ![emmacooper](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@emmacooper](https://discourse.julialang.org/u/emmacooper)\
**Post date:** [May 19, 2025, 9:05pm UTC](https://discourse.julialang.org/t/mapreduce-with-multiple-arguments/129158/3 "2025-05-19T21:05:38Z")

</div>

> [@mbauman](#):
>
> `reduce((x, y) -> merge(x, y, method=:outer), tas)`

Wow, yes I do! Thank you so much.
