Skip to content
Snippets Groups Projects
Commit 3da736a8 authored by kiady.arintsoa's avatar kiady.arintsoa :man_with_turban_tone2:
Browse files

Merge branch 'Use-worksheets' into 'main'

Use worksheets

See merge request kiady.arintsoa/advprog-exercises!5
parents ea07eefd e9352f78
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,4 @@
.metals/
target/
.vscode/
playground.scala
\ No newline at end of file
playground.worksheet.sc
\ No newline at end of file
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)))
}
// 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)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment