Scala: Anonymous function or Generic function , search element in array

//polymorpjic function is a function which conains parameters as of genric types
//also some time known as generic function

object Polymorphicfunc extends App {

def searcharray[A](arr:Array[A],str:A):Int= //polymorphic function or generic function
def loop(n:Int):Int= // type [A] can be anything
if(arr(n)==str) n // search the str variable at index if find retun index
else if (n<0) -1
else loop(n-1) // recursion of loop function




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s