Created
April 13, 2023 20:00
-
-
Save yeswell/228a11017f5f363688430bd7153dab06 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
import { interval, Observable } from 'rxjs'; | |
import { map, withLatestFrom } from 'rxjs/operators'; | |
function addOne(n: number): number { | |
return (n + 1); | |
} | |
function toOdd(n: number): number { | |
return ((n * 2) + 1); | |
} | |
function toNatural(n: number): number { | |
return ((n - 1) / 2); | |
} | |
function toSquare(n: number): number { | |
return (n ** 2); | |
} | |
function generateNaturalNumbers(): Observable <number> { | |
return interval(500); | |
} | |
const naturalNumbers = generateNaturalNumbers(); | |
const smallCathetuses = naturalNumbers.pipe( | |
map(addOne), | |
map(toOdd), | |
); | |
const bigCathetuses = smallCathetuses.pipe( | |
map(toSquare), | |
map(toNatural), | |
); | |
const hypotenuses = bigCathetuses.pipe( | |
map(addOne), | |
); | |
const pythagoreanTriples = smallCathetuses.pipe( | |
withLatestFrom(bigCathetuses, hypotenuses), | |
); | |
pythagoreanTriples.subscribe((value) => { | |
console.log(value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment