Skip to content

Commit 8dff4de

Browse files
committed
add Tuple.sum/1 & Tuple.product/1
1 parent 8d40c49 commit 8dff4de

File tree

7 files changed

+74
-0
lines changed

7 files changed

+74
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\node (t) {\{\}};
2+
3+
\draw [->] (t) -- +(0, -1)
4+
node [below] {$1$};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
\matrix [tuple=a] {
2+
\node [index=1]; & \node [separator]; &
3+
\node [index=2]; & \node [separator]; &
4+
\node [elements between]; & \node [separator]; &
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
\node (t) {\{\}};
2+
3+
\draw [->] (t) -- +(0, -1)
4+
node [below] {$0$};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
\matrix [tuple=a] {
2+
\node [index=1]; & \node [separator]; &
3+
\node [index=2]; & \node [separator]; &
4+
\node [elements between]; & \node [separator]; &
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 + a_2 + \dots + a_n = \displaystyle\sum_{i=1}^n a_i$};
13+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: product/1
3+
url: Tuple/product/1
4+
---
5+
6+
Returns the product of all elements of `tuple`.
7+
8+
{{< figure src="images/functions/Tuple/product-1.svg" >}}
9+
10+
Returns 1 if `tuple` has no elements.
11+
12+
{{< figure src="images/functions/Tuple/product-1.2.svg" >}}
13+
14+
Raises `ArithmeticError` if enumerable contains a non-numeric value.
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: sum/1
3+
url: Tuple/sum/1
4+
---
5+
6+
Returns the sum of all elements of `tuple`.
7+
8+
{{< figure src="images/functions/Tuple/sum-1.svg" >}}
9+
10+
Returns 0 if `tuple` has no elements.
11+
12+
{{< figure src="images/functions/Tuple/sum-1.2.svg" >}}
13+
14+
Raises `ArithmeticError` if enumerable contains a non-numeric value.
15+

data/signatures.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,16 @@
12161216
defmodule Tuple do
12171217
def insert_at(tuple, index, value)
12181218
end
1219+
- name: product/1
1220+
signature: |
1221+
defmodule Tuple do
1222+
def product(tuple)
1223+
end
1224+
- name: sum/1
1225+
signature: |
1226+
defmodule Tuple do
1227+
def sum(tuple)
1228+
end
12191229
- name: to_list/1
12201230
signature: |
12211231
defmodule Tuple do

0 commit comments

Comments
 (0)