title: Kotlin Higher Order Function in ViewModel
body: <p>I am new to kotlin , so need help to understand the code ,I went to a blogs and found something like this and implemented in my code , code work perfect but i can't understand the following things .</p>
  
  <p>Basically , I got lost in how <strong>lazyDefferd</strong> function , how it's works internally.<br>
  a. How generic T is passed .<br>
  b. What it mean by this <code>CoroutineScope.()</code> as i know this is input that i need to pass from the <code>ViewModel</code> but how it's getting pass i can't understand .</p>
  
  <pre><code>interface MovieRepository {
      suspend fun getTopRatedMovie(page:Int): LiveData&lt;out List&lt;TopRatedMovieEntity&gt;&gt;
  }
  </code></pre>
  
  <p>ViewModel :</p>
  
  <pre><code>class TopRatedMovieViewModel(movieRepository: MovieRepository):ViewModel() {
  
     val topMovie by lazyDefferd{
         movieRepository.getTopRatedMovie(1)
     }
  
  }
  
  fun &lt;T&gt; lazyDefferd(block:suspend CoroutineScope.()-&gt;T):Lazy&lt;Deferred&lt;T&gt;&gt;{
      return lazy {
          GlobalScope.async(start = CoroutineStart.LAZY) {
               block.invoke(this)
          }
      }
  }
  </code></pre>