-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): add more verbose logging
- Loading branch information
1 parent
25c1836
commit a3edcf2
Showing
9 changed files
with
87 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
import { flow } from 'fp-ts/lib/function'; | ||
import * as O from 'fp-ts/lib/Option'; | ||
import { verbose } from '../../log'; | ||
|
||
type Fn<T> = (ma: O.Option<T>) => O.Option<T>; | ||
|
||
/** | ||
* Log a message when a pipeline contains `None` and let it continue unchanged. | ||
*/ | ||
export function tapNone<T>(message: string): (ma: O.Option<T>) => O.Option<T> { | ||
export function tapNone<T>(message: string): Fn<T> { | ||
return O.fold<T, O.Option<T>>(function logNoneValue() { | ||
verbose(message); | ||
return O.none; | ||
}, O.of); | ||
} | ||
|
||
/** | ||
* Log a message when a pipeline contains `Some` and let it continue unchanged. | ||
*/ | ||
export function tapSome<T>(message: string): Fn<T> { | ||
return O.map(function logSomeValue(value) { | ||
verbose(message, value); | ||
return value; | ||
}); | ||
} | ||
|
||
/** | ||
* Log both possibilities of an `Option` and let it continue unchanged. | ||
*/ | ||
export function tapOption<T>(message: string): Fn<T> { | ||
return flow(tapSome(message), tapNone(`no ${message}`)); | ||
} |