Created
January 1, 2022 08:34
-
-
Save samuelchanx/1ba7f13c1ba257a917180df4d4eb891c to your computer and use it in GitHub Desktop.
Missed dart extensions like in kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ReturnType run<ReturnType>(ReturnType Function() operation) { | |
| return operation(); | |
| } | |
| extension ScopeFunctionsForObject<T extends Object> on T { | |
| ReturnType let<ReturnType>(ReturnType Function(T item) operationFor) { | |
| return operationFor(this); | |
| } | |
| T also(void Function(T item) operationFor) { | |
| operationFor(this); | |
| return this; | |
| } | |
| } | |
| // Adapted from: https://github.com/YusukeIwaki/dart-kotlin_flavor#let |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment