From e9352f78e459a0b4cd2f5adfb650425f5c3f84cd Mon Sep 17 00:00:00 2001 From: "kiady.arintsoa" <kiady.arintsoa@etu.hesge.ch> Date: Mon, 3 Apr 2023 13:15:54 +0200 Subject: [PATCH] Use worksheets --- .gitignore | 2 +- src/scanRightExample.scala | 26 -------------------------- src/scanRightExample.worksheet.sc | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 27 deletions(-) delete mode 100644 src/scanRightExample.scala create mode 100644 src/scanRightExample.worksheet.sc diff --git a/.gitignore b/.gitignore index bc678b8..cc00482 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ .metals/ target/ .vscode/ -playground.scala \ No newline at end of file +playground.worksheet.sc \ No newline at end of file diff --git a/src/scanRightExample.scala b/src/scanRightExample.scala deleted file mode 100644 index ac13a44..0000000 --- a/src/scanRightExample.scala +++ /dev/null @@ -1,26 +0,0 @@ -package scanRightExample - -@main -def main() = { - // From https://stackoverflow.com/questions/17408880/reduce-fold-or-scan-left-right - val abc = List("A", "B", "C") - - def add(res: String, x: String) = { - // println(s"op: $res + $x = ${res + x}") - res + x - } - - println(abc.scanLeft("z")(add)) - - println(abc.scanRight("z")(add)) - - val funcs = List( - (x: Int) => x + 1, - (x: Int) => x * 2, - (x: Int) => x * x - ) - - println(funcs.scanLeft(2)((v, f) => f(v))) - - println(funcs.reverse.scanLeft(2)((v, f) => f(v))) -} diff --git a/src/scanRightExample.worksheet.sc b/src/scanRightExample.worksheet.sc new file mode 100644 index 0000000..659d704 --- /dev/null +++ b/src/scanRightExample.worksheet.sc @@ -0,0 +1,20 @@ +// From https://stackoverflow.com/questions/17408880/reduce-fold-or-scan-left-right +val abc = List("A", "B", "C") + +def add(res: String, x: String) = { + res + x +} + +println(abc.scanLeft("z")(add)) + +println(abc.scanRight("z")(add)) + +val funcs = List( + (x: Int) => x + 1, + (x: Int) => x * 2, + (x: Int) => x * x +) + +println(funcs.scanLeft(2)((v, f) => f(v))) + +println(funcs.reverse.scanLeft(2)((v, f) => f(v))) -- GitLab