Skip to content

Commit 28c729f

Browse files
committed
add Enum.product(_by)
1 parent 61100ac commit 28c729f

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
\matrix [list=a] {
2+
\node [index=1]; &
3+
\node [index=2]; &
4+
\node [elements between]; &
5+
\node [index=n]; \\
6+
};
7+
8+
\draw [brace] (an.south east) -- (a1.south west);
9+
10+
\draw [->] (last brace) -- +(0, -1)
11+
node [below]
12+
{$a_1 \cdot a_2 \cdot \dots \cdot a_n = \displaystyle\prod_{i=1}^n a_i$};
13+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
\matrix [list=a] {
2+
\node [index=1]; &
3+
\node [index=2]; &
4+
\node [elements between]; &
5+
\node [index=n]; \\
6+
};
7+
8+
\foreach \i in {1,2,n}{
9+
\node (fun\i) [fun, below=.5 of a\i.south];
10+
\draw [->] (a\i.south) -- (fun\i.in);
11+
\draw [->] (fun\i.out) -- +(0, -.5)
12+
node (b\i) [below] {$b_{\i}$};
13+
};
14+
15+
16+
17+
\draw [brace] (bn.south east) -- (b1.south west);
18+
19+
\draw [->] (last brace) -- +(0, -1)
20+
node [below]
21+
{$b_1 \cdot b_2 \cdot \dots \cdot b_n = \displaystyle\prod_{i=1}^n b_i$};
22+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: product_by/2
3+
url: Enum/product_by/2
4+
---
5+
6+
Returns the product of all elements of `enumerable`.
7+
8+
Raises `ArithmeticError` if `enumerable` contains a non-numeric value.
9+
10+
{{< figure src="images/functions/Enum/product_by-2.svg" >}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: product_by/2
3+
url: Enum/product_by/2
4+
---
5+
6+
Maps and computes the product of the given `enumerable` in one pass.
7+
8+
Raises `ArithmeticError` if `fun` returns a non-numeric value.
9+
10+
{{< figure src="images/functions/Enum/product_by-2.svg" >}}

data/signatures.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@
254254
empty_fallback \\ fn -> raise Enum.EmptyError end
255255
)
256256
end
257+
- name: product/1
258+
signature: |
259+
defmodule Enum do
260+
def product(enumerable)
261+
end
262+
- name: product_by/2
263+
signature: |
264+
defmodule Enum do
265+
def product_by(enumerable, fun)
266+
end
257267
- name: random/1
258268
signature: |
259269
defmodule Enum do

0 commit comments

Comments
 (0)