function in kotlin
-------------------------------------------------------------------------------------------------------------------------------
(Extension functions) ---------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
1. can "add" function to the class without declaring it
2. the new added functions behaves like "static"
- this is used to add function in the perdefine class
@for my coustom class
# var student = Student()
# println("Pass status ${student.hasPassed(57)}")
# println("Scholar status ${student.isScholar(57)}")
#
# fun Student.isScholar(marks: Int):Boolean{
# return marks>95
# }
#
# class Student(){
#
# fun hasPassed(marks:Int):Boolean{
# return marks > 40
# }
#
# }
@example for perdefine class
# val str1:String = "hello"
# val str2:String = "world"
# val str3:String = "hy"
#
# println(str3.add(str1,str2))
#
# fun String.add(s1:String,s2:String):String{
# return this+s1+s2
# }
-------------------------------------------------------------------------------------------------------------------------------
(Infix functions) -------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
1. "infix function can be a Membory function or Extension function"
2. they have "single parameter"
3. they have perfix of "infox"
# var student = Student()
# println("Scholar status ${student isScholar 80}")
#
# infix fun Student.isScholar(marks: Int):Boolean{
# return marks>95
# }
#
# class Student()
-------------------------------------------------------------------------------------------------------------------------------
(TailRec functions) -----------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------
1. "use recursion in optimised way"
2. prevent "stack overflowException"
3. perfix of "tailrec" is used
@Fibonacci number
# println(getFibonacciNumber(50000000 , BigInteger("0"),BigInteger("1")))
#
# tailrec fun getFibonacciNumber(n:Int , a:BigInteger , b:BigInteger):BigInteger{
# return if (n==0) b else getFibonacciNumber(n-1,a+b,a)
# }