Last active
August 13, 2020 03:35
-
-
Save leohmoraes/ce2ed2e00562f2358b42c341c82b5047 to your computer and use it in GitHub Desktop.
dart2 - High Order Function
This file contains 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
// https://youtu.be/4EzUtx-Q58I?t=1370 | |
// High-order Function | |
int MyInt = 10; | |
// Add 1 to [1] //adiciona 1 | |
int add1(int a) => a + 1; | |
//Halve [a] //metade | |
int halve(int a) => a ~/ 2; | |
// Aplicar no segundo | |
int applyOn2(int Function(int) fn) => fn(2); | |
void main() { | |
print('applyOn2(add1): ${applyOn2(add1)}'); | |
print('applyOn2(halve): ${applyOn2(halve)}'); | |
} | |
//Teste: https://dartpad.dev/ce2ed2e00562f2358b42c341c82b5047 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment