about summary refs log tree commit diff
path: root/lib/lists.nix
AgeCommit message (Collapse)AuthorFilesLines
2024-04-22lib.lists.ifilter0: initSilvan Mosberger1-1/+49
2024-04-15tree-wide: use mapCartesianProductGabriel Volpe1-3/+19
2024-03-16lib.foldl': document eta expansionJohannes Kirschbauer1-1/+9
2024-03-15lib.foldl': avoid unnecessary function callJohannes Kirschbauer1-3/+1
2024-03-13doc: lib.lists migrate to doc-comments (#294257)Johannes Kirschbauer1-370/+1322
* 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-02-09lib.lists: Remove unneeded polyfillsSilvan Mosberger1-26/+5
Nix 2.3 (the minimum version needed to evaluate Nixpkgs) supports these, so no need to keep them around.
2024-02-03lib: make deprecation warnings consistentAlois Wohlschlager1-3/+3
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.
2023-12-08lib.sort: Make doc consistent with sortOnRobert Hensing1-1/+4
2023-12-08lib.sortOn: initRobert Hensing1-0/+40
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-11-20lib: Take advantage of section descriptionsSilvan Mosberger1-2/+1
See https://github.com/nix-community/nixdoc/releases/tag/v2.6.0
2023-11-14lib.lists.allUnique: initFelix Buehler1-0/+13
2023-09-27lib.lists.foldl': Make strict in the initial accumulatorSilvan Mosberger1-3/+10
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-27lib.lists.foldl': Redo documentationSilvan Mosberger1-7/+48
Co-Authored-By: Robert Hensing <robert@roberthensing.nl>
2023-09-26lib.lists.foldl': Remove fallbackSilvan Mosberger1-1/+1
Nix 2.3, the minimum Nix version supported by Nixpkgs, has `builtins.foldl'` already.
2023-08-14Merge pull request #243511 from tweag/lib.lists.hasPrefixSilvan Mosberger1-0/+34
`lib.lists.{hasPrefix,removePrefix}`: init
2023-07-20lib.lists.commonPrefix: initSilvan Mosberger1-1/+27
2023-07-19lib.lists.findFirstIndex: initSilvan Mosberger1-8/+34
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2023-07-14lib.lists.removePrefix: initSilvan Mosberger1-0/+19
2023-07-14lib.lists.hasPrefix: initSilvan Mosberger1-0/+15
2023-06-06lib.list.findFirst: Make lazierSilvan Mosberger1-2/+32
There's no need to evaluate list elements after a matching element
2023-02-07Merge pull request #206611 from h7x4/lib-lists-add-repeatSilvan Mosberger1-0/+12
lib.lists: add `replicate`
2023-02-06lib.lists: add `replicate`h7x41-0/+12
`replicate` returns n copies of an element as a list. Co-Authored-By: Silvan Mosberger <contact@infinisil.com>
2023-01-30lib: standardise attrset type syntaxColin Arnott1-2/+2
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-02lib: Fix mismatched quotes in `lib.*` doc commentsYoshiRulz1-3/+3
caused problems for automated rich text generation such as https://teu5us.github.io/nix-lib.html#customisation-functions
2022-08-20Fix a typo in the lib.foldr docstringSkyler1-1/+1
- This quote mark should be a backtick - Using a quote mark instead of a backtick breaks formatting when rendering the docs
2022-05-30Fix typo in compareLists docstringmichaelmouf1-1/+1
2022-03-18lib.lists: Use builtins.groupBy for lib.groupBySilvan Mosberger1-8/+9
builtins.groupBy is much more performant. It was introduced in https://github.com/NixOS/nix/pull/5715
2021-11-01lib/lists: mutuallyExclusive function optimizationpolykernel1-5/+2
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-02-08lib: remove mention of flashplayer in docsBernardo Meurer1-1/+1
2021-01-28Deprecate lib.crossListsJacek Galowicz1-1/+3
2020-11-24lib.lists.unique: Switch from recursive function to using a foldadisbladis1-7/+1
This improves performance by ~30-40% for smaller test cases and makes larger cases where my laptop would OOM pass in seconds.
2020-10-22lib: Use Nix's static scope checking, fix error message, optimizeRobert Hensing1-1/+1
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-05-08fix example for foldlDrew Mullen1-2/+2
2019-09-06Merge master into staging-nextFrederik Rietdijk1-1/+1
2019-09-06Fix typo in lists.nixRobert Hensing1-1/+1
2019-08-28Merge staging-next into stagingFrederik Rietdijk1-0/+13
2019-08-26treewide: remove redundant quotesvolth1-2/+2
2019-08-05rename foreach -> forEachdanbst1-3/+3
2019-07-14lib: introduce `foreach` = flip mapdanbst1-0/+13
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-04-12lib: improve the implementation of the unique functionLéo Gaspard1-2/+1
2019-03-29lib: lists: Alias builtins.mapMatthias Beyer1-1/+1
Signed-off-by: Matthias Beyer <mail@beyermatthias.de> Suggested-by: Profpatsch <mail@profpatsch.de>
2018-10-29lib/lists: Update documentation comments for doc generationVincent Ambo1-48/+136
Updates documentation comments with extra information for nixdoc[1] compatibility. [1]: https://github.com/tazjin/nixdoc
2018-09-06lib: move assertMsg and assertOneOf to their own library fileProfpatsch1-2/+2
Since the `assertOneOf` uses `lib.generators`, they are not really trivial anymore and should go into their own library file.
2018-09-06lib/trivial: add a few examples of usage of assertMsg/assertOneOfProfpatsch1-2/+5
2018-07-20[bot]: remove unreferenced codevolth1-1/+0
2018-07-05lib.concatMap and lib.mapAttrs to be builtinsvolth1-1/+1
2018-06-10lib: add groupBy (#38612)volth1-0/+36
2018-04-08lib: add naturalSort (move the example IPs to private space)volth1-2/+2
2018-04-08lib: add naturalSortvolth1-1/+22
2018-02-09Merge pull request #33898 from oxij/nixos/related-packages-v5Graham Christensen1-0/+24
nixos: doc: implement related packages in the manual (again)