This repository was archived by the owner on Apr 2, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { PII, tap, unwrap } from "../index"
2
+
3
+ describe("tap", () => {
4
+ it("should tap inside PII", () => {
5
+ const result = PII("TEST_STRING")
6
+ let b: string | undefined = undefined
7
+ const mapped = tap(a => (b = a), result)
8
+ expect(unwrap(mapped)).toBe(b)
9
+ })
10
+
11
+ it("should tap non PII as well", () => {
12
+ const result = "TEST_STRING"
13
+ let b: string | undefined = undefined
14
+ const mapped = tap(a => (b = a), result)
15
+ expect(unwrap(mapped)).toBe(b)
16
+ })
17
+ })
Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ export function map<T, T2>(
40
40
return PII(fn(unwrap(item)))
41
41
}
42
42
43
+ export function tap<T>(fn: (item: T) => void, item: PII<T>): PII<T>
44
+ export function tap<T>(fn: (item: T) => void, item: T): T
45
+ export function tap<T>(fn: (item: T) => void, item: PII<T> | T): PII<T> | T {
46
+ fn(unwrap(item))
47
+
48
+ return item
49
+ }
50
+
43
51
export function test<T>(fn: (item: T) => boolean, item: PII<T>): boolean
44
52
export function test<T>(fn: (item: T) => boolean, item: T): boolean
45
53
export function test<T>(fn: (item: T) => boolean, item: PII<T> | T): boolean {
You can’t perform that action at this time.
0 commit comments