Compare commits

..

2 Commits

@ -5,7 +5,12 @@ import { AsyncPipe, UpperCasePipe } from '@angular/common';
import { TextPipe } from '../text.pipe';
import { HotelService } from './Parent/services/hotel.service';
import { inject } from '@angular/core';
import { filter, from, map, Observable, range, tap, toArray } from 'rxjs';
import { filter, from, last, map, Observable, range, scan, tap, toArray } from 'rxjs';
interface User {
name: string;
age: number;
}
@Component({
selector: 'app-root',
@ -20,15 +25,35 @@ export class AppComponent {
public hotelService: HotelService = inject(HotelService);
ngOnInit() {
const stream: Observable<number | string> = from([5, 1, 2, 12, 5, 14, 17, 5, "testing"]);
const users = [
{ name: "Max", age: 21 },
{ name: "Peter", age: 31 },
{ name: "Hans", age: 13 },
{ name: "Klaus", age: 51 },
{ name: "Dieter", age: 1 },
{ name: "Jan-Marlon", age: 3 },
]
const stream: Observable<User> = from(users);
stream.pipe(
filter((value) => typeof value === "number"),
tap((value) => console.log("Zahl:" + value)),
filter((value: number) => value % 2 === 0),
tap((value) => console.log("Gerade Zahl: " + value)),
toArray(),
filter((user) => user.age > 18),
scan((acc, user) => acc + user.age, 0),
map((ageSum, index) => ageSum / (index + 1)),
last(),
).subscribe(console.log);
// const stream: Observable<number | string> = from([5, 1, 2, 12, 5, 14, 17, 5, "testing"]);
// stream.pipe(
// filter((value) => typeof value === "number"),
// tap((value) => console.log("Zahl:" + value)),
// filter((value: number) => value % 2 === 0),
// tap((value) => console.log("Gerade Zahl: " + value)),
// toArray(),
//).subscribe(console.log);
}
public test() {