score:6
Accepted answer
the value returned from pascal
is the last expression it contains. you want it to be your evaluation of count
but that's not the last thing. assignments (def, val etc) are of type unit, as you've discovered:
def pascal(c: int, r: int): int = {
count(r,c,1,0) // => int
def count(r: int, c: int, countr: int, lalacount: int): int = {
if (countr < (r + 1)) count(r,c,countr + 1, lalacount + countr)
else (lalacount + c + 1)
} // => unit
}
just move count(r,c,1,0)
after the def
and that should fix the problem.
Source: stackoverflow.com
Related Query
- Recursive function not returning Int
- Scala - recursive function not returning the object
- Why is my Scala function returning type Unit and not whatever is the last line?
- How to throw an exception from a recursive function in scala that returns Int
- Function not returning value when called
- Scala recursive function returning Either
- scala function returning only single value of list but not all why?
- in recursive function case nil is not executed
- Scala recursive function else if returning Unit
- recursive function not recognizing initial input in scala
- scala tail recursion decorator not letting tail recursive function to be called
- try/catch not working when use tail recursive function
- Using rscala eval function for returning values to Scala not working
- Scala: map function not returning desired result
- Task not serializable: java.io.NotSerializableException when calling function outside closure only on classes not objects
- What is the Scala annotation to ensure a tail recursive function is optimized?
- Anonymous recursive function in Scala
- Traversing lists and streams with a function returning a future
- Why to use empty parentheses in Scala if we can just use no parentheses to define a function which does not need any arguments?
- Why does Scala not have a return/unit function defined for each monad (in contrast to Haskell)?
- Scala unexpectedly not being able to ascertain type for expanded function
- java.lang.RuntimeException: java.lang.String is not a valid external type for schema of bigint or int
- Scala String toInt - Int does not take parameters
- Spark Task not serializable with lag Window function
- Why does this Scala function compile when the argument does not conform to the type constraint?
- Aggregate function in spark-sql not found
- Compiler error about class graph being not finitary due to a expansively recursive type parameter
- mapping a Stream with a function returning a Future
- Can a function return one of multiple types which do not share a common ancestor?
- Scala Returning a void function with 0 parameters, ugly syntax?
More Query from same tag
- How do I define json writer for custom object in Play + Scala?
- how to run the yarn commands from a spark application
- Inheritance and (automatic?) type conversion
- Spark write DataFrame out jdbc error
- Expression of type serializable doesn't conform to type Option String scala
- Ensure CSV records in Gatling using feeder
- Matching abc/? in routes file
- Scala List object methods implementation
- Basic FunctionN cov/contravariance
- Why does the same algorithm work in Scala much slower than in C#? And how to make it faster?
- Scala importing a file in all files of a package
- How to create a List of values aggregation after a join on DataFrame elements?
- How to match scala generic type?
- Vector of Any to Shapeless HList
- Understanding parameter types during multidimensional array creation
- Creating Some(object) from Java
- How to set ivy shared repo root with sbt?
- Type bound for two unrelated types
- change a dataframe row value with dynamic number of columns spark scala
- Stream of strings matching a simple regexp in Scala
- Verifying that generic type argument conforms to 2 unrelated types
- How to use the "exists" function of Squeryl?
- Return value from method definition that has multiple case statements
- Error while Passing arguments to methods using scala reflection
- How to order @Before methods
- Convert Future[Seq[(String, String)]] to Future[Seq[(String)]]
- What is the correct way to invoke this Scala method on main?
- Using scala-eclipse for spark
- Isn't lambda function also an object with Function1 trait?
- Is it possible in Scala to create a partial curried function using an anonymous function