Advertisement
Guest User

Untitled

a guest
Sep 17th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 3.90 KB | None | 0 0
  1. unit class DataTable:ver<0.0.1>:auth<github:tushardave26>;                                            
  2.                                                                                                        
  3. #custom types                                                                                          
  4. subset Int-or-Str where Int|Str;                                                                      
  5.                                                                                                        
  6. #attributes                                                                                            
  7. has Array @.data is rw = [];                                                                          
  8. has Int-or-Str @.header is rw = [];                                                                    
  9. has Int $.type is readonly = 0;                                                                        
  10.                                                                                                        
  11. #methods                                                                                              
  12.                                                                                                        
  13. # This method performs several sanity checks.                                                          
  14. method !sanity-check {                                                                                
  15.                                                                                                        
  16.     # 1. check whether all elements of all arrays of array of arrays (i.e. data) is equal or not      
  17.     unless [==] self@!data {                                                                              
  18.         fail "The number of observations in each rows are not equal.!!";                              
  19.     }                                                                                                  
  20.                                                                                                        
  21.     # 2. check whether the number of observation meaning number elements in a row is equal to          
  22.     # number of columns or not                                                                        
  23.     unless @!data.[0].elems == @!header.elems {                                                        
  24.         fail "The number of observations and number of columns are not equal.!!";                      
  25.     }                                                                                                  
  26.                                                                                                        
  27.     # call sanity-check method within it definition                                                    
  28.     #self!sanity-check();                                                                              
  29. }                                                                                                      
  30.                                                                                                        
  31. #my @a = [1,2,3], [4,5,6]; say [==] @a                                                                
  32.                                                                                                        
  33. method dim {                                                                                          
  34.                                                                                                        
  35.     # check the provided data consistency and other possible issues                                    
  36.     self!sanity-check;                                                                                
  37.                                                                                                        
  38.                                                                                                        
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement