Commit graph

104 commits

Author SHA1 Message Date
Philip Taron 1677539966
lib.lists: undeprecate crossLists (#393573) 2025-10-09 22:19:57 +00:00
Luna Nova d1de5d4748
lib.lists: undeprecate crossLists
mapCartesianProduct's output's order relies on the iteration order of the input attrset
encouraging picking non-meaningful names or arbitrary prefixed underscores if your usecase
requires a specific order.

See this thread for examples of clunkiness required to achieve a specific ordering.
https://discourse.nixos.org/t/lib-crosslists-is-deprecated-use-lib-cartesianproductofsets-instead/41824/10
2025-10-09 14:58:51 -07:00
Felix Buehler 06ac3fbebd lib/*: fix docs to use "returns" instead of "return" 2025-09-12 16:16:41 +02:00
YoshiRulz e17a4719a9
lib.toList: fix typo in docs 2025-08-26 04:16:00 +10:00
Martin Weinelt 4bd0b9c7ab
Reapply "Merge remote-tracking branch 'origin/master' into staging-next"
This reverts commit 106b1418bc.

Restores the commits lost during the revert of a merge on staging-next.
2025-08-23 16:06:41 +02:00
Martin Weinelt 106b1418bc Revert "Merge remote-tracking branch 'origin/master' into staging-next"
This reverts commit 28cafe5795, reversing
changes made to 281c9189d4.

Broken merge due to mergiraf removing many newlines from
python-packages.nix.
2025-08-15 13:58:54 +02:00
Johannes Kirschbauer 78ac637056
lib: init lists.uniqueStrings 2025-08-15 11:45:50 +02:00
azahi 9fee9e7371
lib.takeEnd: init 2025-04-13 17:37:35 +03:00
Silvan Mosberger 374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Silvan Mosberger 0f880eb305
lib.dropEnd (#370558) 2025-01-13 21:30:30 +01:00
Silvan Mosberger 7277b3a840
doc: improve lib.compareLists documentation (#368360) 2025-01-13 21:10:51 +01:00
Johannes Kirschbauer 477b98b2a9
doc: improve lib.compareLists documentation 2025-01-09 11:25:44 +01:00
piegames dd7d5339f7 treewide: Fix incorrect string indentations 2025-01-07 19:49:28 +01:00
Robert Hensing 782a0e6581 lib.dropEnd: init
Naming borrowed from Haskell
- `base`: [`dropWhileEnd`]
- `extra`, `mono-traversable`, ...: [`dropEnd`]

[`dropEnd`]: https://hackage.haskell.org/package/mono-traversable-1.0.21.0/docs/Data-Sequences.html#v:dropEnd
[`dropWhileEnd`]: https://hackage.haskell.org/package/base-4.21.0.0/docs/Data-List.html#v:dropWhileEnd
2025-01-03 12:04:06 +01:00
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