Advertisement
Guest User

Reduce!

a guest
Oct 23rd, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.66 KB | None | 0 0
  1. import std.stdio;
  2. import std.algorithm;
  3.  
  4. void main(string[] args) {
  5.   writeln([1,2,3,4,5,6].reduce!"a+b");
  6.   other();
  7. }
  8.  
  9. void other() {
  10.   mixin(q{writeln("hello world");});
  11.  
  12.   const string sfunc = "a - b";
  13.   auto func = delegate (int a, int b) { mixin("return " ~ sfunc ~ ";");};
  14.   writeln([1,2,3,4,5,6].reduce!func);
  15.   writeln([1,2,3,4,5,6].reduce!"a-b");
  16.   writeln([1,2,3,4,5,6].reduce!"a*b");
  17.   writeln([1,2,3,4,5,6].reduce!((a,b) => (a * b) + 2));
  18.   writeln([1,2,3,4,5,6].reduce!( delegate (int a, int b) {return (a * b) + 2;} ));
  19.   writeln([1,2,3,4,5,6].reduce!( delegate (int a, int b) {return a + (b*2);} ));
  20.   writeln([1,2,3,4,5,6].reduce!"a+(b*2)");
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement