Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created February 14, 2018 15:47
Show Gist options
  • Save ajcrites/9a4c63e1915d541861edda31b88a1757 to your computer and use it in GitHub Desktop.
Save ajcrites/9a4c63e1915d541861edda31b88a1757 to your computer and use it in GitHub Desktop.
import { of } from 'rxjs/observable/of';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
const identity = <T, M extends keyof T>(...props: M[]) => map<T, { [M in keyof T]: T[M] }>(val => props.reduce((props, propName) => {
props[propName] = val[propName];
return props;
}, {} as { [M in keyof T]: T[M] }));
interface Somethin {
value: number;
str: string;
}
const smth: Somethin = { value: 0, str: 'str' };
of(smth).pipe(
map(val => val),
identity('str'),
map(({ str }) => str.toLowerCase())
).subscribe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment