{
    "content": [
        {
            "type": "text",
            "text": "# List::MoreUtils (perldoc)\n\n## NAME\n\nList::MoreUtils - Provide the stuff missing in List::Util\n\n## SYNOPSIS\n\n# import specific functions\nuse List::MoreUtils qw(any uniq);\nif ( any { /foo/ } uniq @hasduplicates ) {\n# do stuff\n}\n# import everything\nuse List::MoreUtils ':all';\n# import by API\n# has \"original\" any/all/none/notall behavior\nuse List::MoreUtils ':like0.22';\n# 0.22 + bsearch\nuse List::MoreUtils ':like0.24';\n# has \"simplified\" any/all/none/notall behavior + (n)sortby\nuse List::MoreUtils ':like0.33';\n\n## DESCRIPTION\n\nList::MoreUtils provides some trivial but commonly needed functionality on lists which is not\ngoing to go into List::Util.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **EXPORTS** (1 subsections)\n- **FUNCTIONS** (9 subsections)\n- **ENVIRONMENT**\n- **MAINTENANCE**\n- **CONTRIBUTING**\n- **BUGS**\n- **SUPPORT** (1 subsections)\n- **THANKS** (2 subsections)\n- **TODO**\n- **SEE ALSO**\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "List::MoreUtils",
        "section": "",
        "mode": "perldoc",
        "summary": "List::MoreUtils - Provide the stuff missing in List::Util",
        "synopsis": "# import specific functions\nuse List::MoreUtils qw(any uniq);\nif ( any { /foo/ } uniq @hasduplicates ) {\n# do stuff\n}\n# import everything\nuse List::MoreUtils ':all';\n# import by API\n# has \"original\" any/all/none/notall behavior\nuse List::MoreUtils ':like0.22';\n# 0.22 + bsearch\nuse List::MoreUtils ':like0.24';\n# has \"simplified\" any/all/none/notall behavior + (n)sortby\nuse List::MoreUtils ':like0.33';",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 21,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "EXPORTS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Default behavior",
                        "lines": 40
                    }
                ]
            },
            {
                "name": "FUNCTIONS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Junctions",
                        "lines": 93
                    },
                    {
                        "name": "Transformation",
                        "lines": 171
                    },
                    {
                        "name": "Partitioning",
                        "lines": 49
                    },
                    {
                        "name": "Iteration",
                        "lines": 61
                    },
                    {
                        "name": "Searching",
                        "lines": 91
                    },
                    {
                        "name": "Sorting",
                        "lines": 82
                    },
                    {
                        "name": "Searching in sorted Lists",
                        "lines": 43
                    },
                    {
                        "name": "Operations on sorted Lists",
                        "lines": 26
                    },
                    {
                        "name": "Counting and calculation",
                        "lines": 55
                    }
                ]
            },
            {
                "name": "ENVIRONMENT",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "MAINTENANCE",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "CONTRIBUTING",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 50,
                "subsections": [
                    {
                        "name": "Business support and maintenance",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "THANKS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Tassilo von Parseval",
                        "lines": 26
                    },
                    {
                        "name": "Jens Rehsack",
                        "lines": 12
                    }
                ]
            },
            {
                "name": "TODO",
                "lines": 24,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 20,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "List::MoreUtils - Provide the stuff missing in List::Util\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "# import specific functions\n\nuse List::MoreUtils qw(any uniq);\n\nif ( any { /foo/ } uniq @hasduplicates ) {\n# do stuff\n}\n\n# import everything\n\nuse List::MoreUtils ':all';\n\n# import by API\n\n# has \"original\" any/all/none/notall behavior\nuse List::MoreUtils ':like0.22';\n# 0.22 + bsearch\nuse List::MoreUtils ':like0.24';\n# has \"simplified\" any/all/none/notall behavior + (n)sortby\nuse List::MoreUtils ':like0.33';\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "List::MoreUtils provides some trivial but commonly needed functionality on lists which is not\ngoing to go into List::Util.\n\nAll of the below functions are implementable in only a couple of lines of Perl code. Using the\nfunctions from this module however should give slightly better performance as everything is\nimplemented in C. The pure-Perl implementation of these functions only serves as a fallback in\ncase the C portions of this module couldn't be compiled on this machine.\n",
                "subsections": []
            },
            "EXPORTS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Default behavior",
                        "content": "Nothing by default. To import all of this module's symbols use the \":all\" tag. Otherwise\nfunctions can be imported by name as usual:\n\nuse List::MoreUtils ':all';\n\nuse List::MoreUtils qw{ any firstidx };\n\nBecause historical changes to the API might make upgrading List::MoreUtils difficult for some\nprojects, the legacy API is available via special import tags.\n\nLike version 0.22 (last release with original API)\nThis API was available from 2006 to 2009, returning undef for empty lists on\n\"all\"/\"any\"/\"none\"/\"notall\":\n\nuse List::MoreUtils ':like0.22';\n\nThis import tag will import all functions available as of version 0.22. However, it will import\n\"anyu\" as \"any\", \"allu\" as \"all\", \"noneu\" as \"none\", and \"notallu\" as \"notall\".\n\nLike version 0.24 (first incompatible change)\nThis API was available from 2010 to 2011. It changed the return value of \"none\" and added the\n\"bsearch\" function.\n\nuse List::MoreUtils ':like0.24';\n\nThis import tag will import all functions available as of version 0.24. However it will import\n\"anyu\" as \"any\", \"allu\" as \"all\", and \"notallu\" as \"notall\". It will import \"none\" as\ndescribed in the documentation below (true for empty list).\n\nLike version 0.33 (second incompatible change)\nThis API was available from 2011 to 2014. It is widely used in several CPAN modules and thus\nit's closest to the current API. It changed the return values of \"any\", \"all\", and \"notall\". It\nadded the \"sortby\" and \"nsortby\" functions and the \"distinct\" alias for \"uniq\". It omitted\n\"bsearch\".\n\nuse List::MoreUtils ':like0.33';\n\nThis import tag will import all functions available as of version 0.33. Note: it will not import\n\"bsearch\" for consistency with the 0.33 API.\n"
                    }
                ]
            },
            "FUNCTIONS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Junctions",
                        "content": "*Treatment of an empty list*\nThere are two schools of thought for how to evaluate a junction on an empty list:\n\n*   Reduction to an identity (boolean)\n\n*   Result is undefined (three-valued)\n\nIn the first case, the result of the junction applied to the empty list is determined by a\nmathematical reduction to an identity depending on whether the underlying comparison is \"or\" or\n\"and\". Conceptually:\n\n\"any are true\"      \"all are true\"\n--------------      --------------\n2 elements:     A || B || 0         A && B && 1\n1 element:      A || 0              A && 1\n0 elements:     0                   1\n\nIn the second case, three-value logic is desired, in which a junction applied to an empty list\nreturns \"undef\" rather than true or false\n\nJunctions with a \"u\" suffix implement three-valued logic. Those without are boolean.\n\nall BLOCK LIST\nallu BLOCK LIST\nReturns a true value if all items in LIST meet the criterion given through BLOCK. Sets $ for\neach item in LIST in turn:\n\nprint \"All values are non-negative\"\nif all { $ >= 0 } ($x, $y, $z);\n\nFor an empty LIST, \"all\" returns true (i.e. no values failed the condition) and \"allu\" returns\n\"undef\".\n\nThus, \"allu(@list)\" is equivalent to \"@list ? all(@list) : undef\".\n\nNote: because Perl treats \"undef\" as false, you must check the return value of \"allu\" with\n\"defined\" or you will get the opposite result of what you expect.\n\nany BLOCK LIST\nanyu BLOCK LIST\nReturns a true value if any item in LIST meets the criterion given through BLOCK. Sets $ for\neach item in LIST in turn:\n\nprint \"At least one non-negative value\"\nif any { $ >= 0 } ($x, $y, $z);\n\nFor an empty LIST, \"any\" returns false and \"anyu\" returns \"undef\".\n\nThus, \"anyu(@list)\" is equivalent to \"@list ? any(@list) : undef\".\n\nnone BLOCK LIST\nnoneu BLOCK LIST\nLogically the negation of \"any\". Returns a true value if no item in LIST meets the criterion\ngiven through BLOCK. Sets $ for each item in LIST in turn:\n\nprint \"No non-negative values\"\nif none { $ >= 0 } ($x, $y, $z);\n\nFor an empty LIST, \"none\" returns true (i.e. no values failed the condition) and \"noneu\"\nreturns \"undef\".\n\nThus, \"noneu(@list)\" is equivalent to \"@list ? none(@list) : undef\".\n\nNote: because Perl treats \"undef\" as false, you must check the return value of \"noneu\" with\n\"defined\" or you will get the opposite result of what you expect.\n\nnotall BLOCK LIST\nnotallu BLOCK LIST\nLogically the negation of \"all\". Returns a true value if not all items in LIST meet the\ncriterion given through BLOCK. Sets $ for each item in LIST in turn:\n\nprint \"Not all values are non-negative\"\nif notall { $ >= 0 } ($x, $y, $z);\n\nFor an empty LIST, \"notall\" returns false and \"notallu\" returns \"undef\".\n\nThus, \"notallu(@list)\" is equivalent to \"@list ? notall(@list) : undef\".\n\none BLOCK LIST\noneu BLOCK LIST\nReturns a true value if precisely one item in LIST meets the criterion given through BLOCK. Sets\n$ for each item in LIST in turn:\n\nprint \"Precisely one value defined\"\nif one { defined($) } @list;\n\nReturns false otherwise.\n\nFor an empty LIST, \"one\" returns false and \"oneu\" returns \"undef\".\n\nThe expression \"one BLOCK LIST\" is almost equivalent to \"1 == true BLOCK LIST\", except for\nshort-cutting. Evaluation of BLOCK will immediately stop at the second true value.\n"
                    },
                    {
                        "name": "Transformation",
                        "content": "apply BLOCK LIST\nApplies BLOCK to each item in LIST and returns a list of the values after BLOCK has been\napplied. In scalar context, the last element is returned. This function is similar to \"map\" but\nwill not modify the elements of the input list:\n\nmy @list = (1 .. 4);\nmy @mult = apply { $ *= 2 } @list;\nprint \"\\@list = @list\\n\";\nprint \"\\@mult = @mult\\n\";\nEND\n@list = 1 2 3 4\n@mult = 2 4 6 8\n\nThink of it as syntactic sugar for\n\nfor (my @mult = @list) { $ *= 2 }\n\ninsertafter BLOCK VALUE LIST\nInserts VALUE after the first item in LIST for which the criterion in BLOCK is true. Sets $ for\neach item in LIST in turn.\n\nmy @list = qw/This is a list/;\ninsertafter { $ eq \"a\" } \"longer\" => @list;\nprint \"@list\";\nEND\nThis is a longer list\n\ninsertafterstring STRING VALUE LIST\nInserts VALUE after the first item in LIST which is equal to STRING.\n\nmy @list = qw/This is a list/;\ninsertafterstring \"a\", \"longer\" => @list;\nprint \"@list\";\nEND\nThis is a longer list\n\npairwise BLOCK ARRAY1 ARRAY2\nEvaluates BLOCK for each pair of elements in ARRAY1 and ARRAY2 and returns a new list consisting\nof BLOCK's return values. The two elements are set to $a and $b. Note that those two are aliases\nto the original value so changing them will modify the input arrays.\n\n@a = (1 .. 5);\n@b = (11 .. 15);\n@x = pairwise { $a + $b } @a, @b;     # returns 12, 14, 16, 18, 20\n\n# mesh with pairwise\n@a = qw/a b c/;\n@b = qw/1 2 3/;\n@x = pairwise { ($a, $b) } @a, @b;    # returns a, 1, b, 2, c, 3\n\nmesh ARRAY1 ARRAY2 [ ARRAY3 ... ]\nzip ARRAY1 ARRAY2 [ ARRAY3 ... ]\nReturns a list consisting of the first elements of each array, then the second, then the third,\netc, until all arrays are exhausted.\n\nExamples:\n\n@x = qw/a b c d/;\n@y = qw/1 2 3 4/;\n@z = mesh @x, @y;         # returns a, 1, b, 2, c, 3, d, 4\n\n@a = ('x');\n@b = ('1', '2');\n@c = qw/zip zap zot/;\n@d = mesh @a, @b, @c;   # x, 1, zip, undef, 2, zap, undef, undef, zot\n\n\"zip\" is an alias for \"mesh\".\n\nzip6\nzipunflatten\nReturns a list of arrays consisting of the first elements of each array, then the second, then\nthe third, etc, until all arrays are exhausted.\n\n@x = qw/a b c d/;\n@y = qw/1 2 3 4/;\n@z = zip6 @x, @y;         # returns [a, 1], [b, 2], [c, 3], [d, 4]\n\n@a = ('x');\n@b = ('1', '2');\n@c = qw/zip zap zot/;\n@d = zip6 @a, @b, @c;     # [x, 1, zip], [undef, 2, zap], [undef, undef, zot]\n\n\"zipunflatten\" is an alias for \"zip6\".\n\nlistcmp ARRAY0 ARRAY1 [ ARRAY2 ... ]\nReturns an associative list of elements and every *id* of the list it was found in. Allows easy\nimplementation of @a & @b, @a | @b, @a ^ @b and so on. Undefined entries in any given array are\nskipped.\n\nmy @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen);\nmy @b = qw(two three five seven eleven thirteen seventeen);\nmy @c = qw(one one two three five eight thirteen twentyone);\nmy %cmp = listcmp @a, @b, @c; # returns (one => [0, 2], two => [0, 1, 2], three => [0, 1, 2], four => [0], ...)\n\nmy @seq = (1, 2, 3);\nmy @prim = (undef, 2, 3, 5);\nmy @fib = (1, 1, 2);\nmy %cmp = listcmp @seq, @prim, @fib;\n# returns ( 1 => [0, 2], 2 => [0, 1, 2], 3 => [0, 1], 5 => [1] )\n\narrayify LIST[,LIST[,LIST...]]\nReturns a list consisting of each element of given arrays. Recursive arrays are flattened, too.\n\n@a = (1, [[2], 3], 4, [5], 6, [7], 8, 9);\n@l = arrayify @a;         # returns 1, 2, 3, 4, 5, 6, 7, 8, 9\n\nuniq LIST\ndistinct LIST\nReturns a new list by stripping duplicate values in LIST by comparing the values as hash keys,\nexcept that undef is considered separate from ''. The order of elements in the returned list is\nthe same as in LIST. In scalar context, returns the number of unique elements in LIST.\n\nmy @x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 1 2 3 5 4\nmy $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5\n# returns \"Mike\", \"Michael\", \"Richard\", \"Rick\"\nmy @n = distinct \"Mike\", \"Michael\", \"Richard\", \"Rick\", \"Michael\", \"Rick\"\n# returns \"A8\", \"\", undef, \"A5\", \"S1\"\nmy @s = distinct \"A8\", \"\", undef, \"A5\", \"S1\", \"A5\", \"A8\"\n# returns \"Giulia\", \"Giulietta\", undef, \"\", 156, \"GTA\", \"GTV\", 159, \"Brera\", \"4C\"\nmy @w = uniq \"Giulia\", \"Giulietta\", undef, \"\", 156, \"GTA\", \"GTV\", 159, \"Brera\", \"4C\", \"Giulietta\", \"Giulia\"\n\n\"distinct\" is an alias for \"uniq\".\n\nRT#49800 can be used to give feedback about this behavior.\n\nsingleton LIST\nReturns a new list by stripping values in LIST occurring more than once by comparing the values\nas hash keys, except that undef is considered separate from ''. The order of elements in the\nreturned list is the same as in LIST. In scalar context, returns the number of elements\noccurring only once in LIST.\n\nmy @x = singleton 1,1,2,2,3,4,5 # returns 3 4 5\n\nduplicates LIST\nReturns a new list by stripping values in LIST occurring less than twice by comparing the values\nas hash keys, except that undef is considered separate from ''. The order of elements in the\nreturned list is the same as in LIST. In scalar context, returns the number of elements\noccurring more than once in LIST.\n\nmy @y = duplicates 1,1,2,4,7,2,3,4,6,9; #returns 1,2,4\n\nfrequency LIST\nReturns an associative list of distinct values and the corresponding frequency.\n\nmy @f = frequency values %radionrw; # returns (\n#  'Deutschlandfunk (DLF)' => 9, 'WDR 3' => 10,\n#  'WDR 4' => 11, 'WDR 5' => 14, 'WDR Eins Live' => 14,\n#  'Deutschlandradio Kultur' => 8,...)\n\noccurrences LIST\nReturns a new list of frequencies and the corresponding values from LIST.\n\nmy @o = occurrences ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4);\n#  @o = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]);\n\nmode LIST\nReturns the modal value of LIST. In scalar context, just the modal value is returned, in list\ncontext all probes occurring *modal* times are returned, too.\n\nmy @m = mode ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7);\n#  @m = (7, 4, 8) - bimodal LIST\n\nslide BLOCK LIST\nThe function \"slide\" operates on pairs of list elements like:\n\nmy @s = slide { \"$a and $b\" } (0..3);\n# @s = (\"0 and 1\", \"1 and 2\", \"2 and 3\")\n\nThe idea behind this function is a kind of magnifying glass that is moved along a list and calls\n\"BLOCK\" every time the next list item is reached.\n"
                    },
                    {
                        "name": "Partitioning",
                        "content": "after BLOCK LIST\nReturns a list of the values of LIST after (and not including) the point where BLOCK returns a\ntrue value. Sets $ for each element in LIST in turn.\n\n@x = after { $ % 5 == 0 } (1..9);    # returns 6, 7, 8, 9\n\nafterincl BLOCK LIST\nSame as \"after\" but also includes the element for which BLOCK is true.\n\nbefore BLOCK LIST\nReturns a list of values of LIST up to (and not including) the point where BLOCK returns a true\nvalue. Sets $ for each element in LIST in turn.\n\nbeforeincl BLOCK LIST\nSame as \"before\" but also includes the element for which BLOCK is true.\n\npart BLOCK LIST\nPartitions LIST based on the return value of BLOCK which denotes into which partition the\ncurrent value is put.\n\nReturns a list of the partitions thusly created. Each partition created is a reference to an\narray.\n\nmy $i = 0;\nmy @part = part { $i++ % 2 } 1 .. 8;   # returns [1, 3, 5, 7], [2, 4, 6, 8]\n\nYou can have a sparse list of partitions as well where non-set partitions will be undef:\n\nmy @part = part { 2 } 1 .. 10;            # returns undef, undef, [ 1 .. 10 ]\n\nBe careful with negative values, though:\n\nmy @part = part { -1 } 1 .. 10;\nEND\nModification of non-creatable array value attempted, subscript -1 ...\n\nNegative values are only ok when they refer to a partition previously created:\n\nmy @idx  = ( 0, 1, -1 );\nmy $i    = 0;\nmy @part = part { $idx[$i++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8]\n\nsamples COUNT LIST\nReturns a new list containing COUNT random samples from LIST. Is similar to \"shuffle\" in\nList::Util, but stops after COUNT.\n\n@r  = samples 10, 1..10; # same as shuffle\n@r2 = samples 5, 1..10; # gives 5 values from 1..10;\n"
                    },
                    {
                        "name": "Iteration",
                        "content": "eacharray ARRAY1 ARRAY2 ...\nCreates an array iterator to return the elements of the list of arrays ARRAY1, ARRAY2 throughout\nARRAYn in turn. That is, the first time it is called, it returns the first element of each\narray. The next time, it returns the second elements. And so on, until all elements are\nexhausted.\n\nThis is useful for looping over more than one array at once:\n\nmy $ea = eacharray(@a, @b, @c);\nwhile ( my ($a, $b, $c) = $ea->() )   { .... }\n\nThe iterator returns the empty list when it reached the end of all arrays.\n\nIf the iterator is passed an argument of '\"index\"', then it returns the index of the last\nfetched set of values, as a scalar.\n\neacharrayref LIST\nLike eacharray, but the arguments are references to arrays, not the plain arrays.\n\nnatatime EXPR, LIST\nCreates an array iterator, for looping over an array in chunks of $n items at a time. (n at a\ntime, get it?). An example is probably a better explanation than I could give in words.\n\nExample:\n\nmy @x = ('a' .. 'g');\nmy $it = natatime 3, @x;\nwhile (my @vals = $it->())\n{\nprint \"@vals\\n\";\n}\n\nThis prints\n\na b c\nd e f\ng\n\nslideatatime STEP, WINDOW, LIST\nCreates an array iterator, for looping over an array in chunks of \"$windows-size\" items at a\ntime.\n\nThe idea behind this function is a kind of magnifying glass (finer controllable compared to\n\"slide\") that is moved along a list.\n\nExample:\n\nmy @x = ('a' .. 'g');\nmy $it = slideatatime 2, 3, @x;\nwhile (my @vals = $it->())\n{\nprint \"@vals\\n\";\n}\n\nThis prints\n\na b c\nc d e\ne f g\ng\n"
                    },
                    {
                        "name": "Searching",
                        "content": "firstval BLOCK LIST\nfirstvalue BLOCK LIST\nReturns the first element in LIST for which BLOCK evaluates to true. Each element of LIST is set\nto $ in turn. Returns \"undef\" if no such element has been found.\n\n\"firstvalue\" is an alias for \"firstval\".\n\nonlyval BLOCK LIST\nonlyvalue BLOCK LIST\nReturns the only element in LIST for which BLOCK evaluates to true. Sets $ for each item in\nLIST in turn. Returns \"undef\" if no such element has been found.\n\n\"onlyvalue\" is an alias for \"onlyval\".\n\nlastval BLOCK LIST\nlastvalue BLOCK LIST\nReturns the last value in LIST for which BLOCK evaluates to true. Each element of LIST is set to\n$ in turn. Returns \"undef\" if no such element has been found.\n\n\"lastvalue\" is an alias for \"lastval\".\n\nfirstres BLOCK LIST\nfirstresult BLOCK LIST\nReturns the result of BLOCK for the first element in LIST for which BLOCK evaluates to true.\nEach element of LIST is set to $ in turn. Returns \"undef\" if no such element has been found.\n\n\"firstresult\" is an alias for \"firstres\".\n\nonlyres BLOCK LIST\nonlyresult BLOCK LIST\nReturns the result of BLOCK for the first element in LIST for which BLOCK evaluates to true.\nSets $ for each item in LIST in turn. Returns \"undef\" if no such element has been found.\n\n\"onlyresult\" is an alias for \"onlyres\".\n\nlastres BLOCK LIST\nlastresult BLOCK LIST\nReturns the result of BLOCK for the last element in LIST for which BLOCK evaluates to true. Each\nelement of LIST is set to $ in turn. Returns \"undef\" if no such element has been found.\n\n\"lastresult\" is an alias for \"lastres\".\n\nindexes BLOCK LIST\nEvaluates BLOCK for each element in LIST (assigned to $) and returns a list of the indices of\nthose elements for which BLOCK returned a true value. This is just like \"grep\" only that it\nreturns indices instead of values:\n\n@x = indexes { $ % 2 == 0 } (1..10);   # returns 1, 3, 5, 7, 9\n\nfirstidx BLOCK LIST\nfirstindex BLOCK LIST\nReturns the index of the first element in LIST for which the criterion in BLOCK is true. Sets $\nfor each item in LIST in turn:\n\nmy @list = (1, 4, 3, 2, 4, 6);\nprintf \"item with index %i in list is 4\", firstidx { $ == 4 } @list;\nEND\nitem with index 1 in list is 4\n\nReturns -1 if no such item could be found.\n\n\"firstindex\" is an alias for \"firstidx\".\n\nonlyidx BLOCK LIST\nonlyindex BLOCK LIST\nReturns the index of the only element in LIST for which the criterion in BLOCK is true. Sets $\nfor each item in LIST in turn:\n\nmy @list = (1, 3, 4, 3, 2, 4);\nprintf \"uniqe index of item 2 in list is %i\", onlyidx { $ == 2 } @list;\nEND\nunique index of item 2 in list is 4\n\nReturns -1 if either no such item or more than one of these has been found.\n\n\"onlyindex\" is an alias for \"onlyidx\".\n\nlastidx BLOCK LIST\nlastindex BLOCK LIST\nReturns the index of the last element in LIST for which the criterion in BLOCK is true. Sets $\nfor each item in LIST in turn:\n\nmy @list = (1, 4, 3, 2, 4, 6);\nprintf \"item with index %i in list is 4\", lastidx { $ == 4 } @list;\nEND\nitem with index 4 in list is 4\n\nReturns -1 if no such item could be found.\n\n\"lastindex\" is an alias for \"lastidx\".\n"
                    },
                    {
                        "name": "Sorting",
                        "content": "sortby BLOCK LIST\nReturns the list of values sorted according to the string values returned by the KEYFUNC block\nor function. A typical use of this may be to sort objects according to the string value of some\naccessor, such as\n\nsortby { $->name } @people\n\nThe key function is called in scalar context, being passed each value in turn as both $ and the\nonly argument in the parameters, @. The values are then sorted according to string comparisons\non the values returned. This is equivalent to\n\nsort { $a->name cmp $b->name } @people\n\nexcept that it guarantees the name accessor will be executed only once per value. One\ninteresting use-case is to sort strings which may have numbers embedded in them \"naturally\",\nrather than lexically.\n\nsortby { s/(\\d+)/sprintf \"%09d\", $1/eg; $ } @strings\n\nThis sorts strings by generating sort keys which zero-pad the embedded numbers to some level (9\ndigits in this case), helping to ensure the lexical sort puts them in the correct order.\n\nnsortby BLOCK LIST\nSimilar to sortby but compares its key values numerically.\n\nqsort BLOCK ARRAY\nThis sorts the given array in place using the given compare code. Except for tiny compare code\nlike \"$a <=> $b\", qsort is much faster than Perl's \"sort\" depending on the version.\n\nCompared 5.8 and 5.26:\n\nmy @rl;\nfor(my $i = 0; $i < 1E6; ++$i) { push @rl, rand(1E5) }\nmy $idx;\n\nsub extcmp { $[0] <=> $[1] }\n\ncmpthese( -60, {\n'qsort' => sub {\nmy @qrl = @rl;\nqsort { extcmp($a, $b) } @qrl;\n$idx = bsearchidx { extcmp($, $rl[0]) } @qrl\n},\n'reverse qsort' => sub {\nmy @qrl = @rl;\nqsort { extcmp($b, $a) } @qrl;\n$idx = bsearchidx { extcmp($rl[0], $) } @qrl\n},\n'sort' => sub {\nmy @srl = @rl;\n@srl = sort { extcmp($a, $b) } @srl;\n$idx = bsearchidx { extcmp($, $rl[0]) } @srl\n},\n'reverse sort' => sub {\nmy @srl = @rl;\n@srl = sort { extcmp($b, $a) } @srl;\n$idx = bsearchidx { extcmp($rl[0], $) } @srl\n},\n});\n\n5.8 results\n\ns/iter  reverse sort          sort reverse qsort         qsort\nreverse sort    6.21            --           -0%           -8%          -10%\nsort            6.19            0%            --           -7%          -10%\nreverse qsort   5.73            8%            8%            --           -2%\nqsort           5.60           11%           11%            2%            --\n\n5.26 results\n\ns/iter  reverse sort          sort reverse qsort         qsort\nreverse sort    4.54            --           -0%          -96%          -96%\nsort            4.52            0%            --          -96%          -96%\nreverse qsort  0.203         2139%         2131%            --          -19%\nqsort          0.164         2666%         2656%           24%            --\n\nUse it where external data sources might have to be compared (think of Unix::Statgrab \"tables\").\n\n\"qsort\" is available from List::MoreUtils::XS only. It's insane to maintain a wrapper around\nPerl's sort nor having a pure Perl implementation. One could create a flip-book in same speed as\nPP runs a qsort.\n"
                    },
                    {
                        "name": "Searching in sorted Lists",
                        "content": "bsearch BLOCK LIST\nPerforms a binary search on LIST which must be a sorted list of values. BLOCK must return a\nnegative value if the current element (stored in $) is smaller, a positive value if it is\nbigger and zero if it matches.\n\nReturns a boolean value in scalar context. In list context, it returns the element if it was\nfound, otherwise the empty list.\n\nbsearchidx BLOCK LIST\nbsearchindex BLOCK LIST\nPerforms a binary search on LIST which must be a sorted list of values. BLOCK must return a\nnegative value if the current element (stored in $) is smaller, a positive value if it is\nbigger and zero if it matches.\n\nReturns the index of found element, otherwise -1.\n\n\"bsearchindex\" is an alias for \"bsearchidx\".\n\nlowerbound BLOCK LIST\nReturns the index of the first element in LIST which does not compare *less than val*.\nTechnically it's the first element in LIST which does not return a value below zero when passed\nto BLOCK.\n\n@ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17);\n$lb = lowerbound { $ <=> 2 } @ids; # returns 2\n$lb = lowerbound { $ <=> 4 } @ids; # returns 10\n\nlowerbound has a complexity of O(log n).\n\nupperbound BLOCK LIST\nReturns the index of the first element in LIST which does not compare *greater than val*.\nTechnically it's the first element in LIST which does not return a value below or equal to zero\nwhen passed to BLOCK.\n\n@ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17);\n$lb = upperbound { $ <=> 2 } @ids; # returns 4\n$lb = upperbound { $ <=> 4 } @ids; # returns 14\n\nupperbound has a complexity of O(log n).\n\nequalrange BLOCK LIST\nReturns a pair of indices containing the lowerbound and the upperbound.\n"
                    },
                    {
                        "name": "Operations on sorted Lists",
                        "content": "binsert BLOCK ITEM LIST\nbsearchinsert BLOCK ITEM LIST\nPerforms a binary search on LIST which must be a sorted list of values. BLOCK must return a\nnegative value if the current element (stored in $) is smaller, a positive value if it is\nbigger and zero if it matches.\n\nITEM is inserted at the index where the ITEM should be placed (based on above search). That\nmeans, it's inserted before the next bigger element.\n\n@l = (2,3,5,7);\nbinsert { $ <=> 4 }  4, @l; # @l = (2,3,4,5,7)\nbinsert { $ <=> 6 } 42, @l; # @l = (2,3,4,42,7)\n\nYou take care that the inserted element matches the compare result.\n\nbremove BLOCK LIST\nbsearchremove BLOCK LIST\nPerforms a binary search on LIST which must be a sorted list of values. BLOCK must return a\nnegative value if the current element (stored in $) is smaller, a positive value if it is\nbigger and zero if it matches.\n\nThe item at the found position is removed and returned.\n\n@l = (2,3,4,5,7);\nbremove { $ <=> 4 }, @l; # @l = (2,3,5,7);\n"
                    },
                    {
                        "name": "Counting and calculation",
                        "content": "true BLOCK LIST\nCounts the number of elements in LIST for which the criterion in BLOCK is true. Sets $ for each\nitem in LIST in turn:\n\nprintf \"%i item(s) are defined\", true { defined($) } @list;\n\nfalse BLOCK LIST\nCounts the number of elements in LIST for which the criterion in BLOCK is false. Sets $ for\neach item in LIST in turn:\n\nprintf \"%i item(s) are not defined\", false { defined($) } @list;\n\nreduce0 BLOCK LIST\nReduce LIST by calling BLOCK in scalar context for each element of LIST. $a contains the\nprogressional result and is initialized with 0. $b contains the current processed element of\nLIST and $ contains the index of the element in $b.\n\nThe idea behind reduce0 is summation (addition of a sequence of numbers).\n\nreduce1 BLOCK LIST\nReduce LIST by calling BLOCK in scalar context for each element of LIST. $a contains the\nprogressional result and is initialized with 1. $b contains the current processed element of\nLIST and $ contains the index of the element in $b.\n\nThe idea behind reduce1 is product of a sequence of numbers.\n\nreduceu BLOCK LIST\nReduce LIST by calling BLOCK in scalar context for each element of LIST. $a contains the\nprogressional result and is uninitialized. $b contains the current processed element of LIST and\n$ contains the index of the element in $b.\n\nThis function has been added if one might need the extra of the index value but need an\nindividual initialization.\n\nUse with caution: In most cases \"reduce\" in List::Util will do the job better.\n\nminmax LIST\nCalculates the minimum and maximum of LIST and returns a two element list with the first element\nbeing the minimum and the second the maximum. Returns the empty list if LIST was empty.\n\nThe \"minmax\" algorithm differs from a naive iteration over the list where each element is\ncompared to two values being the so far calculated min and max value in that it only requires\n3n/2 - 2 comparisons. Thus it is the most efficient possible algorithm.\n\nHowever, the Perl implementation of it has some overhead simply due to the fact that there are\nmore lines of Perl code involved. Therefore, LIST needs to be fairly big in order for \"minmax\"\nto win over a naive implementation. This limitation does not apply to the XS version.\n\nminmaxstr LIST\nComputes the minimum and maximum of LIST using string compare and returns a two element list\nwith the first element being the minimum and the second the maximum. Returns the empty list if\nLIST was empty.\n\nThe implementation is similar to \"minmax\".\n"
                    }
                ]
            },
            "ENVIRONMENT": {
                "content": "When \"LISTMOREUTILSPP\" is set, the module will always use the pure-Perl implementation and not\nthe XS one. This environment variable is really just there for the test-suite to force testing\nthe Perl implementation, and possibly for reporting of bugs. I don't see any reason to use it in\na production environment.\n",
                "subsections": []
            },
            "MAINTENANCE": {
                "content": "The maintenance goal is to preserve the documented semantics of the API; bug fixes that bring\nactual behavior in line with semantics are allowed. New API functions may be added over time. If\na backwards incompatible change is unavoidable, we will attempt to provide support for the\nlegacy API using the same export tag mechanism currently in place.\n\nThis module attempts to use few non-core dependencies. Non-core configuration and testing\nmodules will be bundled when reasonable; run-time dependencies will be added only if they\ndeliver substantial benefit.\n",
                "subsections": []
            },
            "CONTRIBUTING": {
                "content": "While contributions are appreciated, a contribution should not cause more effort for the\nmaintainer than the contribution itself saves (see Open Source Contribution Etiquette\n<http://tirania.org/blog/archive/2010/Dec-31.html>).\n\nTo get more familiar where help could be needed - see List::MoreUtils::Contributing.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "There is a problem with a bug in 5.6.x perls. It is a syntax error to write things like:\n\nmy @x = apply { s/foo/bar/ } qw{ foo bar baz };\n\nIt has to be written as either\n\nmy @x = apply { s/foo/bar/ } 'foo', 'bar', 'baz';\n\nor\n\nmy @x = apply { s/foo/bar/ } my @dummy = qw/foo bar baz/;\n\nPerl 5.5.x and Perl 5.8.x don't suffer from this limitation.\n\nIf you have a functionality that you could imagine being in this module, please drop me a line.\nThis module's policy will be less strict than List::Util's when it comes to additions as it\nisn't a core module.\n\nWhen you report bugs, it would be nice if you could additionally give me the output of your\nprogram with the environment variable \"LISTMOREUTILSPP\" set to a true value. That way I know\nwhere to look for the problem (in XS, pure-Perl or possibly both).\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "Bugs should always be submitted via the CPAN bug tracker.\n\nYou can find documentation for this module with the perldoc command.\n\nperldoc List::MoreUtils\n\nYou can also look for information at:\n\n*   RT: CPAN's request tracker\n\n<https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils>\n\n*   AnnoCPAN: Annotated CPAN documentation\n\n<http://annocpan.org/dist/List-MoreUtils>\n\n*   CPAN Ratings\n\n<http://cpanratings.perl.org/dist/List-MoreUtils>\n\n*   MetaCPAN\n\n<https://metacpan.org/release/List-MoreUtils>\n\n*   CPAN Search\n\n<http://search.cpan.org/dist/List-MoreUtils/>\n\n*   Git Repository\n\n<https://github.com/perl5-utils/List-MoreUtils>\n\nWhere can I go for help?\nIf you have a bug report, a patch or a suggestion, please open a new report ticket at CPAN (but\nplease check previous reports first in case your issue has already been addressed) or open an\nissue on GitHub.\n\nReport tickets should contain a detailed description of the bug or enhancement request and at\nleast an easily verifiable way of reproducing the issue or fix. Patches are always welcome, too\n- and it's cheap to send pull-requests on GitHub. Please keep in mind that code changes are more\nlikely accepted when they're bundled with an approving test.\n\nIf you think you've found a bug then please read \"How to Report Bugs Effectively\" by Simon\nTatham: <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>.\n\nWhere can I go for help with a concrete version?\nBugs and feature requests are accepted against the latest version only. To get patches for\nearlier versions, you need to get an agreement with a developer of your choice - who may or not\nreport the issue and a suggested fix upstream (depends on the license you have chosen).\n",
                "subsections": [
                    {
                        "name": "Business support and maintenance",
                        "content": "Generally, in volunteered projects, there is no right for support. While every maintainer is\nhappy to improve the provided software, spare time is limited.\n\nFor those who have a use case which requires guaranteed support, one of the maintainers should\nbe hired or contracted. For business support you can contact Jens via his CPAN email address\nrehsackATcpan.org. Please keep in mind that business support is neither available for free nor\nare you eligible to receive any support based on the license distributed with this package.\n"
                    }
                ]
            },
            "THANKS": {
                "content": "",
                "subsections": [
                    {
                        "name": "Tassilo von Parseval",
                        "content": "Credits go to a number of people: Steve Purkis for giving me namespace advice and James Keenan\nand Terrence Branno for their effort of keeping the CPAN tidier by making List::Utils obsolete.\n\nBrian McCauley suggested the inclusion of apply() and provided the pure-Perl implementation for\nit.\n\nEric J. Roode asked me to add all functions from his module \"List::MoreUtil\" into this one. With\nminor modifications, the pure-Perl implementations of those are by him.\n\nThe bunch of people who almost immediately pointed out the many problems with the glitchy 0.07\nrelease (Slaven Rezic, Ron Savage, CPAN testers).\n\nA particularly nasty memory leak was spotted by Thomas A. Lowery.\n\nLars Thegler made me aware of problems with older Perl versions.\n\nAnno Siegel de-orphaned eacharrayref().\n\nDavid Filmer made me aware of a problem in eacharrayref that could ultimately lead to a\nsegfault.\n\nRicardo Signes suggested the inclusion of part() and provided the Perl-implementation.\n\nRobin Huston kindly fixed a bug in perl's MULTICALL API to make the XS-implementation of part()\nwork.\n"
                    },
                    {
                        "name": "Jens Rehsack",
                        "content": "Credits goes to all people contributing feedback during the v0.400 development releases.\n\nSpecial thanks goes to David Golden who spent a lot of effort to develop a design to support\ncurrent state of CPAN as well as ancient software somewhere in the dark. He also contributed a\nlot of patches to refactor the API frontend to welcome any user of List::MoreUtils - from\nancient past to recently last used.\n\nToby Inkster provided a lot of useful feedback for sane importer code and was a nice sounding\nboard for API discussions.\n\nPeter Rabbitson provided a sane git repository setup containing entire package history.\n"
                    }
                ]
            },
            "TODO": {
                "content": "A pile of requests from other people is still pending further processing in my mailbox. This\nincludes:\n\n*   deleteindex\n\n*   randomitem\n\n*   randomitemdeleteindex\n\n*   listdiffhash\n\n*   listdiffinboth\n\n*   listdiffinfirst\n\n*   listdiffinsecond\n\nThese were all suggested by Dan Muey.\n\n*   listify\n\nAlways return a flat list when either a simple scalar value was passed or an\narray-reference. Suggested by Mark Summersault.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "List::Util, List::AllUtils, List::UtilsBy\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Jens Rehsack <rehsack AT cpan.org>\n\nAdam Kennedy <adamk@cpan.org>\n\nTassilo von Parseval <tassilo.von.parseval@rwth-aachen.de>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "Some parts copyright 2011 Aaron Crane.\n\nCopyright 2004 - 2010 by Tassilo von Parseval\n\nCopyright 2013 - 2017 by Jens Rehsack\n\nAll code added with 0.417 or later is licensed under the Apache License, Version 2.0 (the\n\"License\"); you may not use this file except in compliance with the License. You may obtain a\ncopy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the\nLicense is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\nexpress or implied. See the License for the specific language governing permissions and\nlimitations under the License.\n\nAll code until 0.416 is licensed under the same terms as Perl itself, either Perl version 5.8.4\nor, at your option, any later version of Perl 5 you may have available.\n",
                "subsections": []
            }
        }
    }
}