diff --git a/doc/docs.md b/doc/docs.md index 3df862be50..cefaaa9375 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -602,10 +602,20 @@ Arrays can be efficiently filtered and mapped with the `.filter()` and nums := [1, 2, 3, 4, 5, 6] even := nums.filter(it % 2 == 0) println(even) // [2, 4, 6] +// filter can accept anonymous functions +even_fn := nums.filter(fn (x int) bool { + return x % 2 == 0 +}) +println(even_fn) words := ['hello', 'world'] upper := words.map(it.to_upper()) println(upper) // ['HELLO', 'WORLD'] +// map can also accept anonymous functions +upper_fn := words.map(fn (w string) string { + return w.to_upper() +}) +println(upper_fn) // ['HELLO', 'WORLD'] ``` `it` is a builtin variable which refers to element currently being processed in filter/map methods.