Skip to content

Instantly share code, notes, and snippets.

@guillaumegarcia13
Last active July 31, 2018 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillaumegarcia13/9299d6d05b1ebd8a073b67504c97b970 to your computer and use it in GitHub Desktop.
Save guillaumegarcia13/9299d6d05b1ebd8a073b67504c97b970 to your computer and use it in GitHub Desktop.
Yield example
// Run it live on: https://goo.gl/dgwE2D
class Example {
public getCountries(fields: string[] = ['name', 'alpha2Code', 'translations', 'flag']): Observable<any[]> {
const sep = (function* () {
let call = 0;
while (true) {
yield (call++ === 0) ? '?' : '&';
}
})();
const url = `https://restcountries.eu/rest/v2/all`
+
((fields && fields.length > 0) ? sep.next().value + 'fields=' + fields.join(';')
: '')
;
return url;
}
}
const y = new Example();
document.write('<a href="'+y.getCountries()+'">'+y.getCountries()+'</a>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment