diff runtime/doc/eval.txt @ 20766:821925509d8c v8.2.0935

patch 8.2.0935: flattening a list with existing code is slow Commit: https://github.com/vim/vim/commit/077a1e670ad69ef4cefc22103ca6635bd269e764 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 8 20:50:43 2020 +0200 patch 8.2.0935: flattening a list with existing code is slow Problem: Flattening a list with existing code is slow. Solution: Add flatten(). (Mopp, closes https://github.com/vim/vim/issues/3676)
author Bram Moolenaar <Bram@vim.org>
date Mon, 08 Jun 2020 21:00:04 +0200
parents 661eb972cb22
children 90b96fa35e4b
line wrap: on
line diff
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2451,6 +2451,7 @@ finddir({name} [, {path} [, {count}]])
 				String	find directory {name} in {path}
 findfile({name} [, {path} [, {count}]])
 				String	find file {name} in {path}
+flatten({list} [, {maxdepth}])	List	flatten {list} up to {maxdepth} levels
 float2nr({expr})		Number	convert Float {expr} to a Number
 floor({expr})			Float	round {expr} down
 fmod({expr1}, {expr2})		Float	remainder of {expr1} / {expr2}
@@ -4514,6 +4515,25 @@ findfile({name} [, {path} [, {count}]])	
 		Can also be used as a |method|: >
 			GetName()->findfile()
 
+flatten({list} [, {maxdepth}])					*flatten()*
+		Flatten {list} up to {maxdepth} levels.  Without {maxdepth}
+		the result is a |List| without nesting, as if {maxdepth} is
+		a very large number.
+		The {list} is changed in place, make a copy first if you do
+		not want that.
+							        *E964*
+		{maxdepth} means how deep in nested lists changes are made.
+		{list} is not modified when {maxdepth} is 0.
+		{maxdepth} must be positive number.
+
+		If there is an error the number zero is returned.
+
+		Example: >
+			:echo flatten([1, [2, [3, 4]], 5])
+<			[1, 2, 3, 4, 5] >
+			:echo flatten([1, [2, [3, 4]], 5], 1)
+<			[1, 2, [3, 4], 5]
+
 float2nr({expr})					*float2nr()*
 		Convert {expr} to a Number by omitting the part after the
 		decimal point.