Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
remove some functions with invalid mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjobeki committed Sep 24, 2023
1 parent d9473a7 commit baee7e8
Show file tree
Hide file tree
Showing 194 changed files with 94 additions and 2,796 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ title: lib.cartesianProductOfSets
description: cartesianProductOfSets
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Return the cartesian product of attribute set value combinations.

# Example

```nix
cartesianProductOfSets { a = [ 1 2 ]; b = [ 10 20 ]; }
=> [
{ a = 1; b = 10; }
{ a = 1; b = 20; }
{ a = 2; b = 10; }
{ a = 2; b = 20; }
]
```

# Type

```haskell
cartesianProductOfSets :: AttrSet -> [AttrSet]
```
10 changes: 8 additions & 2 deletions nixpkgs-docs-example/src/content/docs/reference/collect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ title: lib.collect
description: collect
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Recursively collect sets that verify a given predicate named `pred`
from the set `attrs`. The recursion is stopped when the predicate is
from the set `attrs`. The recursion is stopped when the predicate is
verified.

# Example

```nix
collect isList { a = { b = ["b"]; }; c = [1]; }
=> [["b"] [1]]
```

```nix
collect (x: x ? outPath)
{ a = { outPath = "a/"; }; b = { outPath = "b/"; }; }
=> [{ outPath = "a/"; } { outPath = "b/"; }]
```

# Type

```haskell
collect :: (AttrSet -> Bool) -> AttrSet -> [x]
```
25 changes: 15 additions & 10 deletions nixpkgs-docs-example/src/content/docs/reference/concatmapattrs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ title: lib.concatMapAttrs
description: concatMapAttrs
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Map each attribute in the given set and merge them into a new attribute set.

# Type

concatMapAttrs :: (String -> a -> AttrSet) -> AttrSet -> AttrSet

# Example

```nix
concatMapAttrs
(name: value: {
${name} = value;
${name + value} = value;
})
{ x = "a"; y = "b"; }
(name: value: {
${name} = value;
${name + value} = value;
})
{ x = "a"; y = "b"; }
=> { x = "a"; xa = "a"; y = "b"; yb = "b"; }
```

# Type

```haskell
concatMapAttrs :: (String -> a -> AttrSet) -> AttrSet -> AttrSet
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ title: lib.filterAttrs
description: filterAttrs
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Filter an attribute set by removing all attributes for which the
given predicate return false.

# Example

```nix
filterAttrs (n: v: n == "foo") { foo = 1; bar = 2; }
=> { foo = 1; }
```

# Type

```haskell
filterAttrs :: (String -> Any -> Bool) -> AttrSet -> AttrSet
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ title: lib.filterAttrsRecursive
description: filterAttrsRecursive
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Filter an attribute set recursively by removing all attributes for
which the given predicate return false.

# Example

```nix
filterAttrsRecursive (n: v: v != null) { foo = { bar = null; }; }
=> { foo = {}; }
```

# Type

```haskell
filterAttrsRecursive :: (String -> Any -> Bool) -> AttrSet -> AttrSet
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ title: lib.foldAttrs
description: foldAttrs
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Apply fold functions to values grouped by key.

# Example

```nix
foldAttrs (item: acc: [item] ++ acc) [] [{ a = 2; } { a = 3; }]
=> { a = [ 2 3 ]; }
```

# Type

```haskell
foldAttrs :: (Any -> Any -> Any) -> Any -> [AttrSets] -> Any
```
12 changes: 11 additions & 1 deletion nixpkgs-docs-example/src/content/docs/reference/foldlattrs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: lib.foldlAttrs
description: foldlAttrs
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Like builtins.foldl' but for attribute sets.
Iterates over every name-value pair in the given attribute set.
Expand All @@ -16,6 +16,7 @@ which has nothing to do with this function, despite the similar name.

# Example

```nix
foldlAttrs
(acc: name: value: {
sum = acc.sum + value;
Expand All @@ -31,31 +32,40 @@ bar = 10;
sum = 11;
names = ["bar" "foo"];
}
```

```nix
foldlAttrs
(throw "function not needed")
123
{};
->
123
```

```nix
foldlAttrs
(_: _: v: v)
(throw "initial accumulator not needed")
{ z = 3; a = 2; };
->
3
```

The accumulator doesn't have to be an attrset.
It can be as simple as a number or string.

```nix
foldlAttrs
(acc: _: v: acc * 10 + v)
1
{ z = 1; a = 2; };
->
121
```

# Type

```haskell
foldlAttrs :: ( a -> String -> b -> a ) -> a -> { ... :: b } -> a
```
6 changes: 5 additions & 1 deletion nixpkgs-docs-example/src/content/docs/reference/genattrs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ title: lib.genAttrs
description: genAttrs
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Generate an attribute set by mapping a function over a list of
attribute names.

# Example

```nix
genAttrs [ "foo" "bar" ] (name: "x_" + name)
=> { foo = "x_foo"; bar = "x_bar"; }
```

# Type

```haskell
genAttrs :: [ String ] -> (String -> Any) -> AttrSet
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ title: lib.getAttrFromPath
description: getAttrFromPath
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Like `attrByPath`, but without a default value. If it doesn't find the
path it will throw an error.

# Example

```nix
x = { a = { b = 3; }; }
getAttrFromPath ["a" "b"] x
=> 3
```

```nix
getAttrFromPath ["z" "z"] x
=> error: cannot find attribute `z.z'
```

# Type

```haskell
getAttrFromPath :: [String] -> AttrSet -> Any
```
6 changes: 5 additions & 1 deletion nixpkgs-docs-example/src/content/docs/reference/getattrs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ title: lib.getAttrs
description: getAttrs
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Given a set of attribute names, return the set of the corresponding
attributes from the given set.

# Example

```nix
getAttrs [ "a" "b" ] { a = 1; b = 2; c = 3; }
=> { a = 1; b = 2; }
```

# Type

```haskell
getAttrs :: [String] -> AttrSet -> AttrSet
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ title: lib.isDerivation
description: isDerivation
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Check whether the argument is a derivation. Any set with
`{ type = "derivation"; }` counts as a derivation.

# Example

```nix
nixpkgs = import <nixpkgs> {}
isDerivation nixpkgs.ruby
=> true
```

```nix
isDerivation "foobar"
=> false
```

# Type

```haskell
isDerivation :: Any -> Bool
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ title: lib.mapAttrs' (Prime)
description: mapAttrs'
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Like `mapAttrs`, but allows the name of each attribute to be
changed in addition to the value. The applied function should
changed in addition to the value. The applied function should
return both the new name and value as a `nameValuePair`.

# Example

```nix
mapAttrs' (name: value: nameValuePair ("foo_" + name) ("bar-" + value))
{ x = "a"; y = "b"; }
=> { foo_x = "bar-a"; foo_y = "bar-b"; }
```

# Type

```haskell
mapAttrs' :: (String -> Any -> { name :: String; value :: Any; }) -> AttrSet -> AttrSet
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ title: lib.mapAttrsRecursive
description: mapAttrsRecursive
---

import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { LinkCard, CardGrid } from "@astrojs/starlight/components";

Like `mapAttrs`, except that it recursively applies itself to
the *leaf* attributes of a potentially-nested attribute set:
the _leaf_ attributes of a potentially-nested attribute set:
the second argument of the function will never be an attrset.
Also, the first argument of the argument function is a *list*
Also, the first argument of the argument function is a _list_
of the attribute names that form the path to the leaf attribute.

For a function that gives you control over what counts as a leaf,
see `mapAttrsRecursiveCond`.

# Example

```nix
mapAttrsRecursive (path: value: concatStringsSep "-" (path ++ [value]))
{ n = { a = "A"; m = { b = "B"; c = "C"; }; }; d = "D"; }
=> { n = { a = "n-a-A"; m = { b = "n-m-b-B"; c = "n-m-c-C"; }; }; d = "d-D"; }
```

# Type

```haskell
mapAttrsRecursive :: ([String] -> a -> b) -> AttrSet -> AttrSet
```

This file was deleted.

Loading

0 comments on commit baee7e8

Please sign in to comment.