Skip to content

Instantly share code, notes, and snippets.

@freewind
Created June 29, 2014 11:05
Show Gist options
  • Select an option

  • Save freewind/ec1115e56ad2ec64ef10 to your computer and use it in GitHub Desktop.

Select an option

Save freewind/ec1115e56ad2ec64ef10 to your computer and use it in GitHub Desktop.
null
// curry的一个意义是: 方便scala根据第一组参数的内容,推断后面的类型
// scala采用基于流的局部推断,只会从第一组参数中获取类型信息,再用到其它组参数里
// 下面只有sort2不用写Int类型
def sort[T](f: (T,T)=>Boolean)(list:List[T]):List[T] = list
sort[Int]((x,y)=>true)(List(1,2,3))
def sort2[T](list:List[T])(f: (T,T)=>Boolean):List[T] = list
sort2(List(1,2,3))((x,y)=>true)
def sort3[T](list:List[T], f: (T,T)=>Boolean):List[T] = list
sort3[Int](List(1,2,3), (x,y)=>true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment