comparison runtime/doc/eval.txt @ 17674:06c3e15ad84d v8.1.1834

patch 8.1.1834: cannot use a lambda as a method commit https://github.com/vim/vim/commit/22a0c0c4ecd23b6c43f79ba9b92899ca0b426e29 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 9 23:25:08 2019 +0200 patch 8.1.1834: cannot use a lambda as a method Problem: Cannot use a lambda as a method. Solution: Implement ->{lambda}(). (closes https://github.com/vim/vim/issues/4768)
author Bram Moolenaar <Bram@vim.org>
date Fri, 09 Aug 2019 23:30:05 +0200
parents 95c23e180022
children 14ac8c31e598
comparison
equal deleted inserted replaced
17673:3043c52e08e4 17674:06c3e15ad84d
1215 expr8(expr1, ...) |Funcref| function call 1215 expr8(expr1, ...) |Funcref| function call
1216 1216
1217 When expr8 is a |Funcref| type variable, invoke the function it refers to. 1217 When expr8 is a |Funcref| type variable, invoke the function it refers to.
1218 1218
1219 1219
1220 expr8->name([args]) method call *method* 1220 expr8->name([args]) method call *method* *->*
1221 expr8->{lambda}([args])
1221 1222
1222 For methods that are also available as global functions this is the same as: > 1223 For methods that are also available as global functions this is the same as: >
1223 name(expr8 [, args]) 1224 name(expr8 [, args])
1224 There can also be methods specifically for the type of "expr8". 1225 There can also be methods specifically for the type of "expr8".
1225 1226
1226 This allows for chaining, passing the value that one method returns to the 1227 This allows for chaining, passing the value that one method returns to the
1227 next method: > 1228 next method: >
1228 mylist->filter(filterexpr)->map(mapexpr)->sort()->join() 1229 mylist->filter(filterexpr)->map(mapexpr)->sort()->join()
1229 < 1230 <
1231 Example of using a lambda: >
1232 GetPercentage->{x -> x * 100}()->printf('%d%%')
1233
1230 *E274* 1234 *E274*
1231 "->name(" must not contain white space. There can be white space before the 1235 "->name(" must not contain white space. There can be white space before the
1232 "->" and after the "(", thus you can split the lines like this: > 1236 "->" and after the "(", thus you can split the lines like this: >
1233 mylist 1237 mylist
1234 \ ->filter(filterexpr) 1238 \ ->filter(filterexpr)