Last active
December 9, 2017 02:44
-
-
Save bergwerf/5d5bb97add73b347c8867a1119483c98 to your computer and use it in GitHub Desktop.
Currying in Dart
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
typedef R Fn1<R, T1>(T1 arg1); | |
typedef R Fn2<R, T1, T2>(T1 arg1, T2 arg2); | |
Fn1<Fn1<R, T2>, T1> curry12<R, T1, T2>(Fn2<R, T1, T2> fn) { | |
return (T1 arg1) => (T2 arg2) => fn(arg1, arg2); | |
} | |
Fn1<Fn1<R, T1>, T2> curry21<R, T1, T2>(Fn2<R, T1, T2> fn) { | |
return (T2 arg2) => (T1 arg1) => fn(arg1, arg2); | |
} | |
void append(String str, String append) => '$str$append'; | |
void main() { | |
final list = ['World!', 'Dart', 'Is there anybody there?']; | |
list.map((str) => append('Hello, ', str)).forEach(print); | |
list.map(curry12(append)('Hello, ')).forEach(print); | |
list.map(curry21(append)('...')).forEach(print); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment