Commit Graph

90 Commits

Author SHA1 Message Date
Silvan Mosberger 6861ef7707 lib.lists.ifilter0: init 2024-04-22 18:33:14 +02:00
Gabriel Volpe d864c36d57
tree-wide: use mapCartesianProduct 2024-04-15 19:17:53 +02:00
Johannes Kirschbauer c8885b86b2
lib.foldl': document eta expansion 2024-03-16 22:58:14 +01:00
Johannes Kirschbauer 9beef9f1ba
lib.foldl': avoid unnecessary function call 2024-03-15 23:42:48 +01:00
Johannes Kirschbauer fe9e7d313a
doc: lib.lists migrate to doc-comments (#294257)
* doc: lib.lists migrate to doc-comments

* Fix extra indentation of docs lines, remove redundant comments, add inputs docs

* fix: indentation & argument references

---------

Co-authored-by: DS <commits@sidhion.com>
2024-03-13 05:53:42 -07:00
Silvan Mosberger 46fd25dda9 lib.lists: Remove unneeded polyfills
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-09 05:46:05 +01:00
Alois Wohlschlager d33127863e
lib: make deprecation warnings consistent
The deprecation warnings in lib were wildly inconsistent. Different
formulations were used in different places for the same meaning. Some warnings
used builtins.trace instead of lib.warn, which prevents silencing; one even
only had a comment instead. Make everything more uniform.
2024-02-03 19:01:39 +01:00
Robert Hensing 50793752a7 lib.sort: Make doc consistent with sortOn 2023-12-08 22:15:30 +01:00
Robert Hensing 67cc78643d lib.sortOn: init
A more efficient sort in some cases, and often convenient.

This exposes `lib.lists.sortOn` immediately on `lib`, because it is
a sibling of `sort`, which is already present there.
Omitting it would lead to more confusion, and worse outcomes.
There's no confusion about the types `sort` or `sortOn` operate on.

Haskell agrees about the type for `sortOn`, and it is in its `base`.
2023-12-08 22:15:29 +01:00
Silvan Mosberger 055ba65fed lib: Take advantage of section descriptions
See https://github.com/nix-community/nixdoc/releases/tag/v2.6.0
2023-11-20 03:02:11 +01:00
Felix Buehler 66261e9961 lib.lists.allUnique: init 2023-11-14 19:52:32 +01:00
Silvan Mosberger 3b6169f87b lib.lists.foldl': Make strict in the initial accumulator
To maintain backwards compatibility, this can't be changed in the Nix language.
We can however ensure that the version Nixpkgs has the more intuitive behavior.
2023-09-27 02:43:59 +02:00
Silvan Mosberger 857a844ea8 lib.lists.foldl': Redo documentation
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2023-09-27 02:43:36 +02:00
Silvan Mosberger 7a0b5c36c9 lib.lists.foldl': Remove fallback
Nix 2.3, the minimum Nix version supported by Nixpkgs, has
`builtins.foldl'` already.
2023-09-26 18:55:54 +02:00
Silvan Mosberger 87c5a6a84f
Merge pull request #243511 from tweag/lib.lists.hasPrefix
`lib.lists.{hasPrefix,removePrefix}`: init
2023-08-14 21:15:54 +02:00
Silvan Mosberger 7f61b01600 lib.lists.commonPrefix: init 2023-07-20 22:42:01 +02:00
Silvan Mosberger 53dcfd24ad lib.lists.findFirstIndex: init
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-07-19 17:35:28 +02:00
Silvan Mosberger 9fdc0bb2bf lib.lists.removePrefix: init 2023-07-14 19:36:46 +02:00
Silvan Mosberger bc8fbc2572 lib.lists.hasPrefix: init 2023-07-14 19:36:45 +02:00
Silvan Mosberger 9790e70150 lib.list.findFirst: Make lazier
There's no need to evaluate list elements after a matching element
2023-06-06 17:17:32 +02:00
Silvan Mosberger 0a60663e67
Merge pull request #206611 from h7x4/lib-lists-add-repeat
lib.lists: add `replicate`
2023-02-07 06:16:09 +01:00
h7x4 7c4abbf80e
lib.lists: add `replicate`
`replicate` returns n copies of an element as a list.

Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
2023-02-06 20:40:47 +01:00
Colin Arnott 6ff66fcbd7
lib: standardise attrset type syntax
There are a number of different syntaxes used for attrset type
signatures in our doc strings, this change standardises upon one that
uses :: for specifying attribute type, and ; terminators to be
consistent with nix syntax. There are no bugs in the functions
themselves, just that different syntaxes may confuse new users.
2023-01-30 23:53:44 +00:00
YoshiRulz 7fba83890c
lib: Fix mismatched quotes in `lib.*` doc comments
caused problems for automated rich text generation such as
https://teu5us.github.io/nix-lib.html#customisation-functions
2023-01-02 08:25:17 +10:00
Skyler d61bc96d16
Fix a typo in the lib.foldr docstring
- This quote mark should be a backtick
- Using a quote mark instead of a backtick breaks formatting when rendering the docs
2022-08-20 23:58:57 +01:00
michaelmouf b1aa4a7f25
Fix typo in compareLists docstring 2022-05-30 12:14:45 +02:00
Silvan Mosberger 1ad7812c4a lib.lists: Use builtins.groupBy for lib.groupBy
builtins.groupBy is much more performant. It was introduced in
https://github.com/NixOS/nix/pull/5715
2022-03-18 00:05:10 +01:00
polykernel cd6397519f lib/lists: mutuallyExclusive function optimization
The current implementation of `mutuallyExclusive` builds a new list with
length subtracted by one on every recursive call which is expensive. When
b is empty, the function still traverses a in its entirety before returning
a result.

The new implementation uses `any` to check if each element of list b is in
list a using `elem`. This maintains short circuiting when list a or b is empty
and has a worst case time complexity of O(nm).
2021-11-01 16:29:01 -04:00
Bernardo Meurer 6ca28ab28e
lib: remove mention of flashplayer in docs 2021-02-08 09:38:41 -08:00
Jacek Galowicz 577d58a8e0 Deprecate lib.crossLists 2021-01-28 23:49:05 +01:00
adisbladis 85605c8a29
lib.lists.unique: Switch from recursive function to using a fold
This improves performance by ~30-40% for smaller test cases and makes
larger cases where my laptop would OOM pass in seconds.
2020-11-24 14:31:54 +01:00
Robert Hensing afa6c51f27 lib: Use Nix's static scope checking, fix error message, optimize
Nix can perform static scope checking, but whenever code is inside
a `with` expression, the analysis breaks down, because it can't
know statically what's in the attribute set whose attributes were
brought into scope. In those cases, Nix has to assume that
everything works out.

Except it doesnt. Removing `with` from lib/ revealed an undefined
variable in an error message.

If that doesn't convince you that we're better off without `with`,
I can tell you that this PR results in a 3% evaluation performance
improvement because Nix can look up local variables by index.
This adds up with applications like the module system.

Furthermore, removing `with` makes the binding site of each
variable obvious, which helps with comprehension.
2020-10-22 13:46:47 +02:00
Drew Mullen 448d68c511 fix example for foldl 2020-05-08 08:31:27 -04:00
Frederik Rietdijk 66bc7fc1b3 Merge master into staging-next 2019-09-06 22:46:05 +02:00
Robert Hensing a0b743f47c
Fix typo in lists.nix 2019-09-06 20:02:36 +02:00
Frederik Rietdijk 5061fe0c2c Merge staging-next into staging 2019-08-28 08:26:42 +02:00
volth 35d68ef143 treewide: remove redundant quotes 2019-08-26 21:40:19 +00:00
danbst d0413360d3 rename foreach -> forEach 2019-08-05 14:06:20 +03:00
danbst 69920dafbf lib: introduce `foreach` = flip map
The main purpose is to bring attention to `flip map`, which improves
code readablity. It is useful when ad-hoc anonymous function
grows two or more lines in `map` application:

```
      map (lcfg:
        let port = lcfg.port;
            portStr = if port != defaultPort then ":${toString port}" else "";
            scheme = if cfg.enableSSL then "https" else "http";
        in "${scheme}://cfg.hostName${portStr}"
      ) (getListen cfg);
```
Compare this to `foreach`-style:
```
      foreach (getListen cfg) (lcfg:
        let port = lcfg.port;
            portStr = if port != defaultPort then ":${toString port}" else "";
            scheme = if cfg.enableSSL then "https" else "http";
        in "${scheme}://cfg.hostName${portStr}"
      );
```
This is similar to Haskell's `for` (http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Traversable.html#v:for)
2019-07-14 13:29:58 +03:00
Léo Gaspard 8319ead594 lib: improve the implementation of the unique function 2019-04-12 20:08:29 +02:00
Matthias Beyer 3cf40fc794 lib: lists: Alias builtins.map
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Suggested-by: Profpatsch <mail@profpatsch.de>
2019-03-29 14:34:30 +01:00
Vincent Ambo 65f50a9bb0 lib/lists: Update documentation comments for doc generation
Updates documentation comments with extra information for nixdoc[1]
compatibility.

[1]: https://github.com/tazjin/nixdoc
2018-10-29 10:42:43 +01:00
Profpatsch efdf618330 lib: move assertMsg and assertOneOf to their own library file
Since the `assertOneOf` uses `lib.generators`, they are not really trivial
anymore and should go into their own library file.
2018-09-06 18:14:27 +02:00
Profpatsch 3e45b61a99 lib/trivial: add a few examples of usage of assertMsg/assertOneOf 2018-09-06 18:14:27 +02:00
volth 87f5930c3f [bot]: remove unreferenced code 2018-07-20 18:48:37 +00:00
volth e9a6c7cebb lib.concatMap and lib.mapAttrs to be builtins 2018-07-05 03:08:00 +00:00
volth 4e85c4ff27 lib: add groupBy (#38612) 2018-06-10 19:31:09 +02:00
volth 3f8c9106ea
lib: add naturalSort (move the example IPs to private space) 2018-04-08 13:54:39 +00:00
volth 25c2fd80b1 lib: add naturalSort 2018-04-08 13:18:13 +00:00
Graham Christensen 5aabf0fc34
Merge pull request #33898 from oxij/nixos/related-packages-v5
nixos: doc: implement related packages in the manual (again)
2018-02-09 20:36:27 -05:00