Skip to content

Instantly share code, notes, and snippets.

@slorber
Last active August 14, 2016 10:54
Show Gist options
  • Save slorber/aa6b6e0390c1b87db4eb412219b929b0 to your computer and use it in GitHub Desktop.
Save slorber/aa6b6e0390c1b87db4eb412219b929b0 to your computer and use it in GitHub Desktop.
Future/promise vs JS generators
function* findOldestKnownFatherSideAncestor(person) {
let currentPerson = person;
while (currentPerson.fatherId) {
currentPerson = yield call(PersonAPI.getById,currentPerson.fatherId);
}
return currentPerson
}
def findOldestKnownFatherSideAncestor(person: Person): Future[Person] = {
person.fatherId match {
case None => Future(person)
case Some(id) => PersonAPI.getById(id).flatMap(findOldestKnownFatherSideAncestor)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment