v
v copied to clipboard
Allow `it` in any functions
Describe the feature
Imagine you have the following function:
fn get_widget_by_condition(cb fn (widget Widget) bool)
Right now, the only way to call it is to write the following code:
get_widget_by_condition(fn (widget Widget) bool) {
return widget.id == 'button-1'
})
For a simple condition, you need to write a lot of extra code.
The language already has a magic variable it that works in some array methods:
[1,2,3].map(it.str())
So we can extend this syntax to all functions.
And the example from the beginning would look like this:
get_widget_by_condition(it.id == 'button-1')
Much more readable and faster to write.
Use Case
See above
Proposed Solution
See above
Other Information
No response
Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
Version used
V 0.3.3 21b17fe.d563739
Environment details (OS name and version, etc.)
OS: macos, macOS, 13.0.1, 22A400
Processor: 10 cpus, 64bit, little endian, Apple M1 Pro
CC version: Apple clang version 14.0.0 (clang-1400.0.29.202)
getwd: /Users/petrmakhnev
vmodules: /Users/petrmakhnev/.vmodules
vroot: /Users/petrmakhnev/v
vexe: /Users/petrmakhnev/v/v
vexe mtime: 2023-01-31 09:57:40
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 21b17fe.d563739
Git version: git version 2.37.1 (Apple Git-137.1)
Git vroot status: weekly.2023.0
am I correct in inferring that you want to "allow it syntax to define predicates"?