Skip to content

Commit

Permalink
Added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Mar 18, 2023
1 parent d8324de commit fdce8fc
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/yqlib/doc/operators/divide.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Divide

Divide behaves differently according to the type of the LHS:
* strings: split by the divider
* number: arithmetic division

## String split
Given a sample.yml file of:
Expand Down
24 changes: 24 additions & 0 deletions pkg/yqlib/doc/operators/filter.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Filter

Filters an array (or map values) by the expression given. Equivalent to doing `map(select(exp))`.


## Filter array
Given a sample.yml file of:
Expand All @@ -16,3 +20,23 @@ will output
- 2
```
## Filter map values
Given a sample.yml file of:
```yaml
c:
things: cool
frog: yes
d:
things: hot
frog: false
```
then
```bash
yq 'filter(.things == "cool")' sample.yml
```
will output
```yaml
- things: cool
frog: yes
```
5 changes: 5 additions & 0 deletions pkg/yqlib/doc/operators/headers/divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Divide

Divide behaves differently according to the type of the LHS:
* strings: split by the divider
* number: arithmetic division
4 changes: 4 additions & 0 deletions pkg/yqlib/doc/operators/headers/filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Filter

Filters an array (or map values) by the expression given. Equivalent to doing `map(select(exp))`.

3 changes: 3 additions & 0 deletions pkg/yqlib/doc/operators/headers/modulo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Modulo

Arithmetic modulo operator, returns the remainder from dividing two numbers.
2 changes: 2 additions & 0 deletions pkg/yqlib/doc/operators/modulo.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Modulo

Arithmetic modulo operator, returns the remainder from dividing two numbers.
## Number modulo - int
If the lhs and rhs are ints then the expression will be calculated with ints.

Expand Down
8 changes: 8 additions & 0 deletions pkg/yqlib/operator_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ var filterOperatorScenarios = []expressionScenario{
"D0, P[], (!!seq)::[1, 2]\n",
},
},
{
description: "Filter map values",
document: `{c: {things: cool, frog: yes}, d: {things: hot, frog: false}}`,
expression: `filter(.things == "cool")`,
expected: []string{
"D0, P[], (!!seq)::[{things: cool, frog: yes}]\n",
},
},
{
skipDoc: true,
document: `[1,2,3]`,
Expand Down

0 comments on commit fdce8fc

Please sign in to comment.