Skip to content

Commit

Permalink
feat(map): add mapTo() and tap() operators
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Apr 19, 2017
1 parent b724f30 commit e31fba0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main.ts
Expand Up @@ -18,6 +18,7 @@ export {IScheduler} from './lib/Scheduler'
export {ISubscriberFunction} from './lib/SubscriberFunction'
export {ISubscription} from './lib/Subscription'
export {join, flatMap} from './operators/Join'
export {mapTo} from './operators/Map'
export {map} from './operators/Map'
export {merge} from './operators/Merge'
export {multicast} from './operators/Multicast'
Expand All @@ -28,3 +29,4 @@ export {scan} from './operators/Scan'
export {skipRepeats} from './operators/SkipRepeats'
export {slice} from './operators/Slice'
export {switchLatest, switchMap} from './operators/Switch'
export {tap} from './operators/Map'
16 changes: 16 additions & 0 deletions src/operators/Map.ts
Expand Up @@ -46,3 +46,19 @@ export const map = curry(function <T, R> (mapFunction: (a: T) => R, source: IObs
}) as Function &
{<T, R> (mapper: TMapper<T, R>, source: TSource<T>): TResult<R>} &
{<T, R> (mapper: TMapper<T, R>): {(source: TSource<T>): TResult<R>}}

export const tap = curry(function <T> (mapFunction: (a: T) => void, source: IObservable<T>) {
return new MapObservable((a: T) => {
mapFunction(a)
return a
}, source)
}) as Function &
{<T> (mapper: TMapper<T, void>, source: TSource<T>): TResult<void>} &
{<T> (mapper: TMapper<T, void>): {(source: TSource<T>): TResult<void>}}


export const mapTo = curry(function <T extends Function> (mapFunction: T, source: IObservable<T>) {
return new MapObservable(() => mapFunction, source)
}) as Function &
{<T> (mapper: TMapper<T, void>, source: TSource<T>): TResult<void>} &
{<T> (mapper: TMapper<T, void>): {(source: TSource<T>): TResult<void>}}

0 comments on commit e31fba0

Please sign in to comment.