.. role:: ts-api-decorator

####
Lazy
####

.. js:module:: Util
   :noindex:

.. container:: ts-api-section

   .. js:class:: Lazy

      This is used to delay the evaluation of a value.

      Evaluation is completely deferred until ``get()`` is called.
      Evaluation happens no more than once and the obtained value
      is cached for later calls to ``get()``.

      ---

      Example:

      .. code-block::


         const x = Lazy.create(() => {
             console.log("evaluating (x)")
             return 5;
         });
         console.log("created (x)");
         console.log(`(x) is ${x.get()}`);
         console.log(`(x+1) is ${x.get()+1}`);

         // *** Console Output ***
         // created (x)
         // evaluating (x)
         // (x) is 5
         // (x+1) is 6



      ---

      Note: Unlike ``LazyObject<T>``, this can have any type ``T``.



.. container:: api-index-section

   .. rubric:: Properties

   .. rst-class:: api-index-list-item api-kind-property api-parent-kind-class

   * :js:attr:`~Util.Lazy.__Lazy`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~Util.Lazy.get`
   * :js:meth:`~Util.Lazy.create`





------------

Properties
==========

.. container:: ts-api-section

   .. js:attribute:: Lazy.__Lazy

      :type: PhantomMember





Methods
=======

.. rst-class:: ts-api-section

get
---

.. js:method:: Lazy.get()



   Forces the lazy value given at construction and returns it.


   :rtype: T

.. rst-class:: ts-api-section

:ts-api-decorator:`static` create
---------------------------------

.. js:method:: Lazy.create( value)

   :param value: None
   :type value: function


   Creates a new lazy value, which is the result of the supplied function
   once the lazy value is forced.


   :rtype: Lazy <T>




   .. js:function:: value()
      :noindex:



      :rtype: T



