Skip to content

Instantly share code, notes, and snippets.

@frabbit
Created August 3, 2012 18:56
Show Gist options
  • Save frabbit/3250423 to your computer and use it in GitHub Desktop.
Save frabbit/3250423 to your computer and use it in GitHub Desktop.
public static function getFirstPath (from:ClassType, to:ClassType):Option<Path>
{
function loop(from:ClassType, to:ClassType, path:Path)
{
trace(loop);
return if (ClassTypes.eq(from, to)) {
Some(path);
} else {
var fromSuper = function ()
{
return
if (from.superClass != null)
{
var r = loop(from.superClass.t.get(), to, path.concat([SuperClass]));
r;
}
else None;
}
var fromInterf = function ()
{
return from.interfaces.foldLeftWithIndex(
function (acc:Option<Path>, cur, index)
{
return acc.orElse(
function () return loop(cur.t.get(), to, path.concat([InterfaceAt(index)]))
);
}, None);
}
fromSuper().orElse(fromInterf);
}
}
trace(loop);
return loop(from, to, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment