diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-07-14 18:18:48 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-07-14 19:36:45 +0200 |
commit | bc8fbc25723b05e0f909faa6589641867200775b (patch) | |
tree | 5f19cfd37b053399fc51ceb1f045cec496d5bf4b /lib/lists.nix | |
parent | a4f7840e1813bc389995083fac2b3bcd0ca6823d (diff) | |
download | nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.tar nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.tar.gz nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.tar.bz2 nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.tar.lz nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.tar.xz nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.tar.zst nixpkgs-bc8fbc25723b05e0f909faa6589641867200775b.zip |
lib.lists.hasPrefix: init
Diffstat (limited to 'lib/lists.nix')
-rw-r--r-- | lib/lists.nix | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index 5d9af0cf711..e12bc9048ef 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -612,6 +612,21 @@ rec { # Input list list: sublist count (length list) list; + /* Whether the first list is a prefix of the second list. + + Type: hasPrefix :: [a] -> [a] -> bool + + Example: + hasPrefix [ 1 2 ] [ 1 2 3 4 ] + => true + hasPrefix [ 0 1 ] [ 1 2 3 4 ] + => false + */ + hasPrefix = + list1: + list2: + take (length list1) list2 == list1; + /* Return a list consisting of at most `count` elements of `list`, starting at index `start`. |