# Filament API

• ### chart

data
required
x
null
xlabel
null
y
null
ylabel
null
type
bar
size
null
name
null

Draws a chart. Type can be either 'bar' or 'scatter'.

a
required
b
required

Adds two values. Can be two numbers, with or without units. Can also be two lists. Or a number and a list. Follows the rules of all binary operations.

// use the operator form 4 + 2 = 6
// use the function form add(4,2) = 6
// number + list 4 + [2,3,4] = [6,7,8]
// list + list adds pairwise [1,2,3] + [4,5,6] = [5,7,9]
• ### subtract

a
required
b
required

subtracts two values. Can be two numbers, with or without units. Can also be two lists. Or a number and a list. Follows the rules of all binary operations.

//list - list [1,2,3] - [4,5,6] = [-3,-3,-3]
• ### multiply

a
required
b
required

Multiplies two values. Can be two numbers, with or without units. Can also be two lists. Or a number and a list. Follows the rules of all binary operations.

// use the operator form 4 * 2 = 8
// use the function form multiply(4,2) = 8
// number + list 4 * [2,3,4] = [8,12,16]
// list + list adds pairwise [1,2,3] * [4,5,6] = [4,10,18]
• ### divide

a
required
b
required

Divides two values. Can be two numbers, with or without units. Can also be two lists. Or a number and a list. Follows the rules of all binary operations.

// use the operator form 4 / 2 = 2
// use the function form divide(4,2) = 2
// number + list 4 / [2,3,4] = [2,1.333,1]
// list + list adds pairwise [1,2,3] / [4,5,6] = [0.25,0.2,0.5]
• ### power

a
required
b
required

raises a value to a power. Can be two numbers, with or without units. Can also be two lists. Or a number and a list. Follows the rules of all binary operations.

// use the operator form 4 ** 2 = 16
// use the function form power(4,2) = 16
// number + list 4 ** [2,3,4] = [16,64,256]
// list + list adds pairwise [1,2,3] ** [4,5,6] = [1, 32, 729]
• ### sqrt

a
required

returns the square root of a scalar value. If the value has a unit, the return will be in the same unit. Can also work on lists by applying the square root to each value in the list. Follows the rules of all unary operations.

• ### negate

a
required

returns the negation of the value

• ### factorial

a
required

returns the factorial of the number

• ### sin

a
required

returns the sine of the angle specified in radians

• ### cos

a
required

returns the cosine of the angle specified in radians

• ### tan

a
required

returns the tangent of the angle specified in radians

• ### abs

a
required

returns the absolute value of the value

• ### mod

a
required
b
required

performs remainder division

8 mod 5 = 3
• ### lessthan

a
required
b
required

returns true of the first value is less than the other

//operator form
• ### is_prime

n
required

Returns true if the number is prime, false otherwise.

• ### range

max
required
min
0
step
1

creates a new list of numbers, from min to max, counting by step. If min is left out it defaults to 0. If step is left out it defaults to 1. *note* the count will always go up to max, but not include it. Thus `range 5` returns `[0,1,2,3,4]`

// List from 0 to 13: range(5) = [0,1,2,3,4]
// same with max: range(max:5) = [0,1,2,3,4]
// 103 to 108 range(min:103, max:108) = [103,104,105,106,107]
// multiples of 5 up to 100: range(100, step:5) = [0,4,9]
• ### length

data
required

returns length of list

length ([1,8,2]) = 2
• ### take

data
REQUIRED
count
REQUIRED

returns part of the list. positive count takes from the beginning. negative count takes from the end

data << range(0,10) take(data, 2) = [0, 1]
data << range(0,10) take(data, -2) = [8,9]
• ### drop

data
REQUIRED
count
REQUIRED

removes part of the list and returns the rest. positive count drops from the start. negative count drops from the end.

data << range(0,10) drop(data,2) = [2,3,4,5,6,7,8,9]
data << range(0,10) drop(data,-2) = [0,1,2,3,4,5,6,7]
• ### join

data
REQUIRED
more
REQUIRED

Joins two lists. returns the new combined list.

join([1,2], [99,100]) = [1,2,99,100]
• ### map

data
REQUIRED
with
REQUIRED

applies the function 'with' to every element of the list, creating a new list

data << range(3) map(data, with: x => x*2) // returns [2,4,6],
double << (x) => { x * 2 } range(10) >> map(with:double) // returns [1,2,3,5,7]
• ### select

data
REQUIRED
where
REQUIRED

return a subset of a list based on if the 'where' function returns true or false

//is_prime is a built in function that returns true or false if the number is prime select(range(10), where:is_prime) // returns [1,2,3,5,7]

0
{
1
2
3
4
5
6
7
d
8
a
9
t
10
a
11
:
12
R
13
E
14
Q
15
U
16
I
17
R
18
E
19
D
20
,
21
22
23
24
25
26
27
o
28
r
29
d
30
e
31
r
32
:
33
"
34
a
35
s
36
c
37
e
38
n
39
d
40
i
41
n
42
g
43
"
44
45
46
47
48
49
50
b
51
y
52
:
53
n
54
u
55
l
56
l
57
58
59
}
60
61
62
@
63
s
64
u
65
m
66
m
67
a
68
r
69
y
70
(
71
r
72
e
73
t
74
u
75
r
76
n
77
s
78
79
a
80
81
s
82
o
83
r
84
t
85
e
86
d
87
88
c
89
o
90
p
91
y
92
93
o
94
f
95
96
t
97
h
98
e
99
100
l
101
i
102
s
103
t
104
.
105
106
s
107
e
108
t
109
110
t
111
h
112
e
113
114
o
115
r
116
d
117
e
118
r
119
120
t
121
o
122
123
'
124
a
125
s
126
c
127
e
128
n
129
d
130
i
131
n
132
g
133
'
134
135
o
136
r
137
138
'
139
d
140
e
141
s
142
c
143
e
144
n
145
d
146
i
147
n
148
g
149
'
150
.
151
152
153
154
s
155
o
156
r
157
t
158
159
b
160
y
161
162
p
163
a
164
r
165
t
166
167
o
168
f
169
170
t
171
h
172
e
173
174
v
175
a
176
l
177
u
178
e
179
180
u
181
s
182
i
183
n
184
g
185
186
t
187
h
188
e
189
190
`
191
b
192
y
193
`
194
195
p
196
a
197
r
198
a
199
m
200
e
201
t
202
e
203
r
204
.
205
206
207
)
208
209
210
@
211
e
212
x
213
a
214
m
215
p
216
l
217
e
218
219
220
s
221
o
222
r
223
t
224
(
225
[
226
4
227
2
228
,
229
2
230
,
231
4
232
]
233
)
234
235
236
/
237
/
238
r
239
e
240
t
241
u
242
r
243
n
244
s
245
246
[
247
2
248
,
249
4
250
,
251
4
252
2
253
]
254
255

• ### reverse

data
REQUIRED

returns a copy of the list with a reverse order

reverse([42,2,4]) //returns [4,2,42]
• ### sum

data
REQUIRED

adds a list of numbers together

sum([42,2,4]) // returns 48
• ### max

data
REQUIRED

returns the biggest element in the list

max([4,2,42]) //returns 42
• ### min

data
REQUIRED

returns the smallest element in the list

min([4,2,42]) //returns 2