Given a Function1
and a Function0
,
val f = () => "toto"
val g = (s : String) => s.length
Is there a better way to compose them ?
val h : () => Int = () => g.apply(f())
Given a Function1
and a Function0
,
val f = () => "toto"
val g = (s : String) => s.length
Is there a better way to compose them ?
val h : () => Int = () => g.apply(f())
That looks good, I'd .toString
the length
for a string and use straight g(...)
instead of g.apply(...)
:
val f = () => "toto"
val g = (s: String) => s.length.toString
val h: () => String = () => g(f())
You can use compose:
val h: Unit => Int = {s: String => s.length} compose {_: Unit => "toto"}