How to make this method generic in Scala -


this simple function given index, item in array last

e.g. given val arr = array(1,2,3) , val = 0; return 3

  def findindexfromlast(arr: array[relationship], i: int): relationship = {     val cur =     val size = arr.length      arr(size - - 1)   } 

i want make generic , able accept array of type

if make 1st argument seq(), take many different types of collections input.

def fromend[t](coll: seq[t], index: int):t = coll.reverse(index)  fromend(array(1,3,5,7,9), 0)                 // res0: int = 9 fromend(list('x','y','q','b'), 3)            // res1: char = x fromend(vector(2.2, 5.4, 7.7), 2)            // res2: double = 2.2 fromend(stream(true, true, false, true), 1)  // res3: boolean = false 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -