Commit Graph

123 Commits

Author SHA1 Message Date
Eman Resu
2fe51f1a7a lib.lists.findFirstIndex: reimplement without indexing 2026-08-06 18:59:56 -04:00
Eman Resu
2221cbb4aa lib.lists: remove assertMsg usage
assertMsg sends our error message through a function call, even if the
error condition doesn't trigger. This requires a lot of thunk allocation
that can be easily avoided.
2026-06-30 21:38:22 -04:00
Eman Resu
4b623fa2b8 lib.lists.reverseList: avoid subtraction 2026-06-24 18:30:03 -04:00
Eman Resu
4e2f331f87 lib.lists.toposort: avoid reversing element causing a cycle 2026-06-24 18:29:22 -04:00
Eman Resu
7d2f66c0ad lib.lists.toposort: avoid extra function calls while recursing 2026-06-24 18:29:21 -04:00
Eman Resu
099a322b3a lib.lists.listDfs: compare to [] instead of checking length 2026-06-24 18:29:21 -04:00
Eman Resu
0f096eb287 lib.lists.flatten: save function call when recursing 2026-06-24 18:29:21 -04:00
Eman Resu
986cf9adb8 lib.lists.init: rewrite to not call take 2026-06-24 18:29:21 -04:00
Eman Resu
09b8cbd5d9 lib.lists.dropEnd: rewrite to not use sublist 2026-06-24 18:29:21 -04:00
Eman Resu
bb3308e01e lib.lists.takeEnd: rewrite to not call sublist 2026-06-24 18:29:20 -04:00
Eman Resu
3621649b19 lib.lists.drop: rewrite to not call sublist 2026-06-24 18:29:20 -04:00
Eman Resu
097288cc6f lib.lists.take: rewrite to not call sublist 2026-06-24 18:29:20 -04:00
Eman Resu
261b8489a0 lib.lists.foldl': avoid builtins lookups 2026-06-24 18:29:20 -04:00
İlkecan Bozdoğan
e394a579b0 lib: update type signatures
- concrete types start with uppercase: Int, String, Bool, Derivation,
  etc.
- type variables start with lowercase: a, b, etc.
- list:
  - use `[x]` for homogeneous lists instead of `List x` or `[ x ]`
  - use `List` for heterogeneous lists (not that common in `lib`)
- attr:
  - use `AttrSet` for a generic attribute set type
  - use `{ key1 :: Type1; key2 :: Type2; ... }` for adding signatures
    for known attribute names and types
  - use `{ key1 = value1; key2 = value2; ... }` for adding attributes
    with known literals
  - end with an ellipsis (`...`) if the set can contain unknown
    attributes
  - use `{ [String] :: x }` if all the attributes has the same type `x`
- prefer `Any` over `a` if the latter is not reused
2026-03-04 00:10:00 +03:00
İlkecan Bozdoğan
64a8ada54e lib: add type signature to some of the functions 2026-03-02 15:46:43 +00:00
Glen Huang
0445cc8aab lib.lists.replaceElemAt: init
It's very easy to resort to lib.take + lib.drop to accomplish this, but it's not obvious that it actually performs quite badly.

Replacing an item in a list should be a relative common operation.
2026-01-12 11:58:42 +00:00
Anton Mosich
367d102c09 docs/lib: use backticks for nix names 2025-11-29 21:46:54 +01:00
Robert Schütz
fafebf715d lib.concatAttrValues: init
This is useful for adding all optional-dependencies to the
nativeCheckInputs of Python packages.
2025-11-27 21:44:14 -08:00
Aliaksandr
f4d36941eb lib: deprecate fold 2025-10-30 16:56:49 +02:00
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