Default parameters, function type examples fixed, tuples with named entries

This commit is contained in:
Andrey Breslav
2010-11-25 16:51:30 +03:00
parent 73b12271c0
commit dd49fc6ce2
8 changed files with 84 additions and 18 deletions
+3 -3
View File
@@ -24,11 +24,11 @@ class Graph<V, E> {
fun neighbours(v : Vertex<V>) = edges.filter{it.from == v}.map{it.to} // type is IIterable<Vertex<V>>
fun dfs(handler : {V => ()}) {
fun dfs(handler : {(V) : Unit}) {
val visited = new HashSet<Vertex<V>>()
vertices.foreach{dfs(it, visited, handler)}
fun dfs(current : Vertex<V>, visited : ISet<Vertex<V>>, handler : {V => ()}) {
fun dfs(current : Vertex<V>, visited : ISet<Vertex<V>>, handler : {(V) : Unit}) {
if (!visited.add(current))
return
handler(current)
@@ -36,7 +36,7 @@ class Graph<V, E> {
}
}
public fun traverse(pending : IPushPop<Vertex<V>>, visited : ISet<Vertex<V>>, handler : {V => ()}) {
public fun traverse(pending : IPushPop<Vertex<V>>, visited : ISet<Vertex<V>>, handler : {(V) : Unit}) {
vertices.foreach {
if (!visited.add(it))
continue