Skip to content

Commit 2186777

Browse files
authored
Merge pull request #180 from itchyny/implement-abs
Implement abs/0 filter
2 parents 23187ab + 52bfba1 commit 2186777

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

prelude.jq

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ def not: if . then false else true end;
22
def select(f): if f then . else empty end;
33
def map(f): [.[] | f];
44
def map_values(f): .[] |= f;
5+
def abs: if . < 0 then - . else . end;
56

67
def isfinite: isinfinite | not;
78
def nulls: select(type == "null");

tests/from_manual/functions.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
use crate::test;
22

3+
test!(
4+
abs1,
5+
r#"
6+
map(abs)
7+
"#,
8+
r#"
9+
[-10, -1.1, -1e-1]
10+
"#,
11+
r#"
12+
[10,1.1,1e-1]
13+
"#
14+
);
15+
316
test!(
417
length1,
518
r#"

0 commit comments

Comments
 (0)