-
Notifications
You must be signed in to change notification settings - Fork 7
/
number.libsonnet
48 lines (44 loc) · 1.03 KB
/
number.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';
{
'#': d.pkg(
name='number',
url='github.com/jsonnet-libs/xtd/number.libsonnet',
help='`number` implements helper functions for processing number.',
),
'#inRange':: d.fn(
'`inRange` returns true if `v` is in the given from/to range.`',
[
d.arg('v', d.T.number),
d.arg('from', d.T.number),
d.arg('to', d.T.number),
]
),
inRange(v, from, to):
v > from && v <= to,
'#maxInArray':: d.fn(
'`maxInArray` finds the biggest number in an array',
[
d.arg('arr', d.T.array),
d.arg('default', d.T.number, default=0),
]
),
maxInArray(arr, default=0):
std.foldl(
std.max,
std.set(arr),
default,
),
'#minInArray':: d.fn(
'`minInArray` finds the smallest number in an array',
[
d.arg('arr', d.T.array),
d.arg('default', d.T.number, default=0),
]
),
minInArray(arr, default=0):
std.foldl(
std.min,
std.set(arr),
default,
),
}