scala - currying: How to make first input as optional? -


i learning scala , concept of currying. doing

scala> def div(a:int)(b:int) = a/b div: (a: int)(b: int)int  scala> div(10)(2) res9: int = 5  scala> val d = div(10)_ d: int => int = <function1>  scala> d(5) res10: int = 2  scala> val e = div _ (2) <console>:1: error: ';' expected '(' found.        val e = div _ (2)                      ^  scala>  

question
- how can make a optional , not b?

you can fix b , function int => int, need keep parentheses, , unfortunately annotate type:

scala> div(_: int)(2) res7: int => int = <function1>  scala> res7(10) res8: int = 5  scala> res7(2) res9: int = 1 

a isn't "optional", it's parameter in resulting function.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -