Created
February 14, 2018 15:47
-
-
Save ajcrites/9a4c63e1915d541861edda31b88a1757 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { 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