while reviewing a tutorial I saw a code piece, to understand this try to write a sample function and call it.
since I am new to scala do not find where to start.
val flow3: Flow[Int, Int, NotUsed] = Flow[Int].statefulMapConcat {
() =>
var sequence = 0
println("statefulMapConcat func call")
i =>
sequence = sequence + i
List(sequence)
}
in the above two things are strange for me
- () => why no parameter
- () => and i => // are they parameter, what kind of style is this. which is calling actual function. and how we can write a function to call this
definition is :
def statefulMapConcat[T](f: () ⇒ Out ⇒ immutable.Iterable[T]): Repr[T] =
via(new StatefulMapConcat(f))
my tries!!
def suffix(x: String): String = x + ".zip"
// not sure this is true
def test1(f: String ⇒ String ⇒ String): String = f("a1")("a2") + "a3"
// not sure this is also a true definition
def test2(f: String ⇒ String ⇒ String): String = f + "a4"
// compile is okay but can not call this
var mytest= test1{
a => a + "a5"
b => b + "a6"
}
// giving even compile time error
test(suffix(suffix("")))