Created
August 3, 2012 19:53
-
-
Save frabbit/3250869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function getFirstPath (from:ClassType, to:ClassType):Option<Path> | |
{ | |
function loop(from:ClassType, to:ClassType, path:Path) | |
{ | |
trace(loop); // boom, loop is null in my case | |
function findInSuperOrInterface () | |
{ | |
function findInSuper () | |
{ | |
var sc = from.superClass; | |
return if (sc != null) loop(sc.t.get(), to, path.concat([SuperClass])) else None; | |
} | |
function findInInterfaces () | |
{ | |
function findInInterface (cur, index) return loop(cur.t.get(), to, path.concat([InterfaceAt(index)])); | |
function findFirst (acc:Option<Path>, cur, index) return acc.orElse(findInInterface.partial1_2(cur, index)); | |
return from.interfaces.foldLeftWithIndex(findFirst, None); | |
} | |
return findInSuper().orElse(findInInterfaces); | |
} | |
return if (ClassTypes.eq(from, to)) Some(path) else findInSuperOrInterface(); | |
} | |
trace(loop); // #function:3, everything is fine here | |
return loop(from, to, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment