Skip to content

Commit

Permalink
Merge pull request #180 from itchyny/implement-abs
Browse files Browse the repository at this point in the history
Implement abs/0 filter
  • Loading branch information
MiSawa authored Mar 5, 2024
2 parents 23187ab + 52bfba1 commit 2186777
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions prelude.jq
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ def not: if . then false else true end;
def select(f): if f then . else empty end;
def map(f): [.[] | f];
def map_values(f): .[] |= f;
def abs: if . < 0 then - . else . end;

def isfinite: isinfinite | not;
def nulls: select(type == "null");
Expand Down
13 changes: 13 additions & 0 deletions tests/from_manual/functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
use crate::test;

test!(
abs1,
r#"
map(abs)
"#,
r#"
[-10, -1.1, -1e-1]
"#,
r#"
[10,1.1,1e-1]
"#
);

test!(
length1,
r#"
Expand Down

0 comments on commit 2186777

Please sign in to comment.