Tharun Thennarasu
5bcb08ea03
lib.hasAttrByPath: fix typo ( #302042 )
2024-04-06 11:24:44 +02:00
Daniel Sidhion
d784fc138d
Apply suggestions from code review
2024-03-19 18:03:31 -07:00
Johannes Kirschbauer
56b5634a90
doc: manual fixup after migration
2024-03-19 22:01:38 +01:00
Johannes Kirschbauer
f917ed536b
doc: migrate lib.attrsets to use doc-comments
2024-03-15 17:18:35 +01:00
Silvan Mosberger
012faf046f
Merge pull request #292941 from adisbladis/lib-getattrfrompath-env
...
lib.getAttrFromPath: Don't use errorMessage variable
2024-03-06 19:41:34 +01:00
Silvan Mosberger
2dc95cded0
Merge pull request #292938 from adisbladis/mapattrsrecursivecond-env
...
lib.mapAttrsRecursiveCond: Eliminate intermediate one intermediate variable environment
2024-03-06 19:40:52 +01:00
Silvan Mosberger
b180a6af30
Merge pull request #292937 from adisbladis/zipattrs-env
...
lib.zipAttrs: Remove needless function wrapping
2024-03-06 19:39:48 +01:00
Silvan Mosberger
0d49917ded
Merge pull request #292934 from adisbladis/lib-choosedevoutput
...
lib.chooseDevOutputs: Remove needless function wrapping
2024-03-06 19:39:30 +01:00
Valentin Gagarin
73c0b48dd6
doc: add details on mapAttrsRecursive[Cond]
( #293509 )
...
* doc: add details on `mapAttrsRecursive[Cond]`
from first reading it wasn't clear that `f` also takes the current
attribute path. also the value f receives is tricky due to how the
condition is evaluated.
Co-authored-by: Daniel Sidhion <DanielSidhion@users.noreply.github.com>
2024-03-06 10:21:23 +01:00
adisbladis
948e5b841d
lib.getAttrFromPath: Don't use errorMessage variable
...
We can just pass the error message on without creating an environment.
2024-03-03 16:30:00 +13:00
adisbladis
34fefe4e16
lib.mapAttrsRecursiveCond: Eliminate intermediate one intermediate variable environment
2024-03-03 16:18:38 +13:00
adisbladis
4338bfde09
lib.zipAttrs: Remove needless function wrapping
...
Returning the partially applied `zipAttrsWith fn` is the same as `sets: zipAttrsWith fn sets`.
2024-03-03 16:17:49 +13:00
adisbladis
3ee9d185f3
lib.chooseDevOutputs: Remove needless function wrapping
...
Returning the partially applied `map getDev` is the same as `drvs: map getDev drvs`.
2024-03-03 16:03:01 +13:00
Silvan Mosberger
31d23ba418
lib.attrsets: 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:03 +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
a7aa95db53
lib/attrsets: Document and link Nix language operators
2023-12-13 18:38:41 +01:00
Robert Hensing
7d993b9521
lib.attrsets.hasAttrByPath: Document law and laziness, and test it
2023-12-08 23:19:09 +01:00
Robert Hensing
72bd4bbb58
lib.attrsets.longestValidPathPrefix: init
...
Allows finding the most specific path that exists.
This is useful for error messages relating to attribute paths.
2023-12-08 23:15:13 +01:00
Robert Hensing
51357572f2
Merge pull request #269552 from adisbladis/lib-matchattrs-list-allocs
...
lib.attrsets.matchAttrs: Avoid some list allocations when walking structure
2023-11-27 14:44:37 +01:00
adisbladis
544a1d375b
lib.attrsets.attrByPath: Don't allocate one extra list per lookup recursion
...
Using `tail` in a recursive loop like this needlessly allocates.
This changes the loop to look up by list index instead.
2023-11-27 11:37:57 +13:00
adisbladis
7e07b3ecd5
lib.attrsets.hasAttrByPath: Don't allocate one extra list per lookup recursion
...
Using `tail` in a recursive loop like this needlessly allocates.
This changes the loop to look up by list index instead.
2023-11-27 11:37:56 +13:00
adisbladis
013a0a1357
lib.attrsets.matchAttrs: Avoid some list allocations when walking structure
...
Benchmarks (`nix-instantiate ./. -A python3`):
- Before:
``` json
{
"cpuTime": 0.29049500823020935,
"envs": {
"bytes": 4484216,
"elements": 221443,
"number": 169542
},
"gc": {
"heapSize": 402915328,
"totalBytes": 53086800
},
"list": {
"bytes": 749424,
"concats": 4242,
"elements": 93678
},
"nrAvoided": 253991,
"nrFunctionCalls": 149848,
"nrLookups": 49612,
"nrOpUpdateValuesCopied": 1587837,
"nrOpUpdates": 10104,
"nrPrimOpCalls": 130356,
"nrThunks": 358981,
"sets": {
"bytes": 30423600,
"elements": 1859999,
"number": 41476
},
"sizes": {
"Attr": 16,
"Bindings": 16,
"Env": 16,
"Value": 24
},
"symbols": {
"bytes": 236145,
"number": 24453
},
"values": {
"bytes": 10502520,
"number": 437605
}
}
```
- After:
``` json
{
"cpuTime": 0.2946169972419739,
"envs": {
"bytes": 3315224,
"elements": 172735,
"number": 120834
},
"gc": {
"heapSize": 402915328,
"totalBytes": 48718432
},
"list": {
"bytes": 347568,
"concats": 4242,
"elements": 43446
},
"nrAvoided": 173252,
"nrFunctionCalls": 101140,
"nrLookups": 73595,
"nrOpUpdateValuesCopied": 1587837,
"nrOpUpdates": 10104,
"nrPrimOpCalls": 83067,
"nrThunks": 304216,
"sets": {
"bytes": 29704096,
"elements": 1831673
,
"number": 24833
},
"sizes": {
"Attr": 16,
"Bindings": 16,
"Env": 16,
"Value": 24
},
"symbols": {
"bytes": 236145,
"number": 24453
},
"values": {
"bytes": 8961552,
"number": 373398
}
}
```
2023-11-27 11:20:50 +13: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
Silvan Mosberger
5323fbf703
Merge pull request #254452 from flyingcircusio/lib-attrsToList
...
lib.attrsets.attrsToList: add function
2023-10-10 19:49:17 +02:00
Oliver Schmidt
d70633f91c
lib.attrsets.attrsToList: add function
...
For transforming back between lists and attrsets, it makes sense to have
a quasi-inverse of `builtins.listToAttrs` available as a library
function.
Co-authored-by: Silvan Mosberger <github@infinisil.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-10-10 16:11:01 +02:00
Silvan Mosberger
dd72ff27f7
lib.attrsets.foldlAttrs: Make stricter
...
See the parent commit for the same change to lib.lists.foldl'
2023-09-27 02:43:59 +02: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
fa503f4b92
lib.attrsets.mergeAttrsList: init
...
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-07-18 20:27:15 +02:00
figsoda
12e01c677c
lib/attrsets: remove unused let bindings
2023-06-23 09:41:04 +00:00
Robert Hensing
5319ddf7dc
lib.concatMapAttrs: Simplify stack trace
2023-05-31 14:57:37 +02:00
zimbatm
ad0b21fbbc
lib: add missing removeAttrs builtin
...
I'm expecting all the builtins.* functions to be available in lib.*
2023-04-19 21:27:38 +02:00
hsjobeki
15a8d05ba5
init: lib.foldlAttrs
...
- provide comprehensive example
- add unit test
2023-03-11 10:42:00 +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
Adam Joseph
a4e3e16258
Update lib/attrsets.nix
...
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-01-25 02:52:54 +00:00
Adam Joseph
ee00af7a32
attrsets: clarify that mapAttrs maps over *leaf* attrs
2023-01-22 15:19:09 -08: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
hsjobeki
5ff21bfc73
attrsets: fix and add some doc types
2022-12-24 14:08:11 +01:00
figsoda
695d4bc76b
lib: fix typos
2022-12-17 18:59:29 -05:00
Ryan Mulligan
ac1ae0a58e
doc: auto-generate asserts and attrset library docs
...
If all the docs are auto-generated, it should be easier to convert
them to Commonmark.
Co-Authored-By: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
2022-12-08 22:58:22 +01:00
figsoda
f993f8a186
lib/attrsets: add concatMapAttrs
2022-11-17 10:41:53 -05:00
figsoda
4536ebad69
lib/attrsets: simplify chooseDevOutputs
2022-11-17 09:41:47 -05:00
Adam Joseph
037cf2fad1
unionOfDisjoint: use builtins.intersectAttrs
...
This brings two benefits:
1. The complete list of collisions is printed in the whenever any colliding
attribute is accessed.
2. The sets are intersected using a C++ primitive, which runs in O(n) time
(intersecting pre-sorted lists) with small constants rather than interpreted
Nix code.
Thanks to @toonn for prompting this improvement.
2022-09-25 00:09:15 -07:00
Adam Joseph
99da193877
note that unionOfDisjoint
is commutative, unlike //
2022-09-12 12:59:16 -07:00
Adam Joseph
47de66b1a4
lib/attrsets.nix: add unionOfDisjoint
2022-09-12 12:53:31 -07:00
Robert Hensing
4d2237c841
lib.foldAttrs: Clarify example
2022-05-10 07:01:00 +02:00
Robert Hensing
5ff918bf55
Merge pull request #147077 from Infinisil/updateAttrPaths
...
Introduce `lib.updateManyAttrsByPath`
2022-03-19 19:00:03 +01:00
Silvan Mosberger
85003ecdbb
lib.attrsets: Introduce updateManyAttrsByPath
2022-03-18 00:08:29 +01:00
Silvan Mosberger
71b130c581
lib.attrsets: Introduce showAttrPath
2022-03-18 00:05:08 +01:00
Robert Hensing
3ddac7a41a
lib.isDerivation: Simplify
2022-03-09 15:48:30 +01:00
John Rinehart
5688e7ff35
fix: typo in lib/attrsets.nix
2022-02-10 01:16:20 +02:00