Tag: map

Simple RxJS Examples

import * as Rx from "rxjs";

let myArray = [1,2,'3','foo', 'bar', 'phi', 3,4,5, '7'];

let stream$ = Rx.Observable.interval(300).take(10)
    .map (x => parseInt(myArray[x]))
    .filter(x => !isNaN(x))
    .reduce((i,j) => {
    console.log(`Addition von ${i} mit ${j} = ${i+j}`);
    return i+j;

let result$ = stream$;

    x => console.log(x),
    err => console.log(err),
    () => console.log ('done')

Lodash related Examples


Creates an array of values by running each element in collection thru iteratee.

_.map(obj, (v, k) => ({key: k, value: v}))

mapValues & keyBy

mapValues Creates an object with the same keys as object and values generated by running each own enumerable string keyed property of object thru iteratee.

keyBy Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The corresponding value of each key is the last element responsible for generating the key.

var result = _.mapValues(_.keyBy(input, 'key'), 'value');

Rendering Data from Observables

Elvis Operator within Template

{{ (__responseData | async)?.calculation | json }}

Or with ngFor

  selector: 'my-app',
  providers: [HTTP_PROVIDERS],
  template: `
    <div *ngFor="let calculation of calculations | async">
      Gross: {{ calculation.gross }}<br>
      Net: {{ calculation.net }}
  directives: [NgFor]
export class App {
  calculations: Observable<{gross:number; net:number}[]>;

  constructor(private _http: Http) {
    this.calculations = this._http.get("./data.json")
                            .map(res => res.json().calculation)

>> See plunker here

Copyright © 2020 EBIA

Theme by Anders NorenUp ↑