1
1
package ktee
2
2
3
- import ktee.KTee.Companion.debug
4
3
import org.slf4j.Logger
5
4
6
- class KTee {
7
- companion object {
8
- var debugChanged = false
9
- private set
10
-
11
- /* *
12
- * If debug is set to false, all tee
13
- * functions won't output anything.
14
- *
15
- * Variable can be set only once!
16
- */
17
- var debug = true
18
- @Synchronized set(value) {
19
- if (! debugChanged) { debugChanged = true ; field = value }
20
- else throw IllegalStateException (" Variable debug has already been set once." )
21
- }
22
- } }
23
-
24
5
/* *
25
6
* Prints the value to the stdout and returns the same value. Useful when chaining
26
7
* methods. For example:
@@ -30,53 +11,53 @@ class KTee {
30
11
* myList.map(fn).tee(">>> ").reduce(fn)
31
12
*
32
13
*/
33
- fun <T > T.tee (marker : String = "") = apply { if (debug) println (marker + this ) }
14
+ fun <T > T.tee (marker : String = "") = apply { println (marker + this ) }
34
15
35
16
/* *
36
17
*
37
18
* executes the lambda with the value of the chain and writes the
38
19
*
39
20
*/
40
- inline fun <T > T.tee (fn : (T ) -> String ) = apply { if (debug) println (fn(this )) }
21
+ inline fun <T > T.tee (fn : (T ) -> String ) = apply { println (fn(this )) }
41
22
42
23
/* *
43
24
* logs the value to the given logger at info level. Message can be customized using message parameter
44
25
*/
45
26
fun <T > T.teeToInfo (logger : Logger , message : String = "{}")
46
- = apply { if (debug) logger.info(message, this ) }
27
+ = apply { logger.info(message, this ) }
47
28
48
29
/* *
49
30
* Evaluates the lambda and logs the result (of evaluation) to the given logger at info level
50
31
*
51
32
*/
52
33
inline fun <T > T.teeToInfo (logger : Logger , fn : (T ) -> String )
53
- = apply { if (debug) logger.info(fn(this ), this ) }
34
+ = apply { logger.info(fn(this ), this ) }
54
35
55
36
/* *
56
37
* logs the value to the given logger at info level. Message can be customized using message parameter
57
38
*/
58
39
fun <T > T.teeToDebug (logger : Logger , message : String = "{}")
59
- = apply { if (debug) logger.debug(message, this ) }
40
+ = apply { logger.debug(message, this ) }
60
41
61
42
/* *
62
43
* Evaluates the lambda and logs the result (of evaluation) to the given logger at debug level
63
44
*
64
45
*/
65
46
inline fun <T > T.teeToDebug (logger : Logger , fn : (T ) -> String )
66
- = apply { if (debug) logger.debug(fn(this ), this ) }
47
+ = apply { logger.debug(fn(this ), this ) }
67
48
68
49
/* *
69
50
* logs the value to the given logger at trace level. Message can be customized using message parameter
70
51
*/
71
52
fun <T > T.teeToTrace (logger : Logger , message : String = "{}")
72
- = apply { if (debug) logger.trace(message, this ) }
53
+ = apply { logger.trace(message, this ) }
73
54
74
55
/* *
75
56
* Evaluates the lambda and logs the result (of evaluation) to the given logger at trace level
76
57
*
77
58
*/
78
59
inline fun <T > T.teeToTrace (logger : Logger , fn : (T ) -> String )
79
- = apply { if (debug) logger.trace(fn(this ), this ) }
60
+ = apply { logger.trace(fn(this ), this ) }
80
61
81
62
82
63
0 commit comments