@@ -363,17 +363,32 @@ object CallByNeed:
363
363
/** Initializes a class that allows for suspending evaluation of a value until it is needed. Evaluation of a value via `.value` can only
364
364
* happen once.
365
365
*/
366
+ def createLazy [A ](a : () => A ): CallByNeed [A ] = new CallByNeed (a, () => false )
367
+
368
+ /** Initializes a class that allows for suspending evaluation of a value until it is needed. Evaluation of a value via `.value` can only
369
+ * happen once.
370
+ *
371
+ * If by-name parameter causes serialization issue, use [[createLazy ]].
372
+ */
366
373
def apply [A ](a : => A ): CallByNeed [A ] = new CallByNeed (() => a, () => false )
367
374
368
375
/** Initializes a class that allows for suspending evaluation of a value until it is needed. Evaluation of a value via `.value` can only
369
376
* happen once. Evaluation of a value via `.valueEvaluator.map(evaluator => evaluator())` will happen every time the evaluator is called
370
377
*/
378
+ def createValueEvaluator [A ](a : () => A ): CallByNeed [A ] = new CallByNeed (a, () => true )
379
+
380
+ /** Initializes a class that allows for suspending evaluation of a value until it is needed. Evaluation of a value via `.value` can only
381
+ * happen once. Evaluation of a value via `.valueEvaluator.map(evaluator => evaluator())` will happen every time the evaluator is called
382
+ *
383
+ * If by-name parameter causes serialization issue, use [[withValueEvaluator ]].
384
+ */
371
385
def withValueEvaluator [A ](a : => A ): CallByNeed [A ] = new CallByNeed (() => a, () => true )
372
386
end CallByNeed
373
387
374
388
// Both params are later nullified to reduce overhead and increase performance.
375
389
// The supportDynamicValueEvaluation is passed as a function so that it can be nullified. Otherwise, there is no need for the function value.
376
- final class CallByNeed [+ A ](private [this ] var eval : () => A , private var supportDynamicValueEvaluation : () => Boolean ) extends Serializable {
390
+ final class CallByNeed [+ A ] private (private [this ] var eval : () => A , private var supportDynamicValueEvaluation : () => Boolean )
391
+ extends Serializable {
377
392
378
393
// This second constructor is necessary to support backwards compatibility for v1.3.6 and earlier
379
394
def this (eval : () => A ) = this (eval, () => false )
0 commit comments