message: String?) {
                  
                  
                   
                  
                  
                      companion object {
                  
                  
                   
                  
                  
                          // In case of Success,set status as
                  
                  
                          // Success and data as the response
                  
                  
                          fun <T> success(data: T?): CommentApiState<T> {
                  
                  
                              return CommentApiState(Status.SUCCESS, data, null)
                  
                  
                          }
                  
                  
                   
                  
                  
                          // In case of failure ,set state to Error ,
                  
                  
                          // add the error message,set data to null
                  
                  
                          fun <T> error(msg: String): CommentApiState<T> {
                  
                  
                              return CommentApiState(Status.ERROR, null, msg)
                  
                  
                          }
                  
                  
                   
                  
                  
                          // When the call is loading set the state
                  
                  
                          // as Loading and rest as null
                  
                  
                          fun <T> loading(): CommentApiState<T> {
                  
                  
                              return CommentApiState(Status.LOADING, null, null)
                  
                  
                          }
                  
                  
                      }
                  
                  
                  }
                  
                  
                   
                  
                  
                  // An enum to store the
                  
                  
                  // current state of api call
                  
                  
                  enum class Status {
                  
                  
                      SUCCESS,
                  
                  
                      ERROR,
                  
                  
                      LOADING
                  
                  
                  }
                  
                  
                
 Tagich
                          
                        
                      
                    
                    
                    
                    
                      Автор вопроса
                      
                      
                        
                          Tagich
                          
                        
                      
                    
                    
                    
                    
                      Автор вопроса
                    
                    
                  не первый раз видел такую конструкцию , кто может объяснить для чего это ?
Обсуждают сегодня