• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Why is function is returning kotlin.Unit

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fun lambda(i:Int,j:Int):Int{
   return i+j
   }
fun lmbd(a:Int,b:Int,fn:(Int,Int)->Int){
   fn(a,b)
   }
fun main(args: Array<String>){
   println("${lmbd(67,97,::lambda)}")
   }

Returns Unit. Why?
 
gunslinger & author
Posts: 151
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first glance it looks like your lmbd function returns Unit (i.e., nothing). If you want it to return a value, you need to add :Int to the signature and add a "return" statement inside the function.
 
Jayakumar Kulandaivel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kenneth A. Kousen,
Thank you!
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!