Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
vituri committed May 11, 2024
1 parent 292c513 commit 6e5a1e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/src/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ flatten_dfr(ds, n = 2)

If you want to convert the inner dictionaries/arrays to json (useful when saving to a relational database), use the function

```@examples 1
```@example 1
flatten_dfr_json(ds, n = 1)
```

Expand Down
14 changes: 7 additions & 7 deletions docs/src/modify.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@ Functions to modify, filter and discard elements of a collection.

`modify` applies a function `f` to each element of `x`.

```@examples modify
```@example modify
x = [1:4;]
modify!(x, x->x^2)
x
```

It also work on dictionaries, keeping the keys intact:
```@examples modify
```@example modify
d = Dict(i => i for i in [1:4;])
modify(d, x->x^2)
```

We can also modify only when a function `p` is true:
```@examples modify
```@example modify
y = [1:6;]
modify_if(y, x->x^2, isodd)
```

## Filtering
We can discard some elements of `x` when a function `p` is false:

```@examples keep
```@example keep
x = [1:4;]
keep(x, isodd)
```

This is the same as base Julia `filter(p, x)`. It also work on dictionaries:

```@examples keep
```@example keep
d = Dict(i => i for i in [1:4;])
keep(x, isodd)
```

If we want to apply `p` to the keys of a dictionary, use
```@examples keep
```@example keep
d = Dict(i => i^2 for i in [1:4;])
keep_keys(d, isodd)
```

There is also the negation of `keep`: `discard`. It's definition is trivial: `discard(x, p) = keep(x, !p)`.

When we want to throw away "length zero elements", use `compact`:
```@examples keep
```@example keep
x = [1, [1, 2], nothing, [], ""]
compact(x)
```
Expand Down

0 comments on commit 6e5a1e1

Please sign in to comment.