Scala entry notes - Method Memo

Operation list

List List1 = Val ( "Hello Java", "Hello Scala C Hello", "Hi C ++") 

// + flattened space separated 
Val list1.split List2 = ( "") .flatten 
Val list3 = list.flatMap (_. Split ( "") 

// parallel sum calculation 
Val ARR = the Array (1, 2,. 3,. 4,. 5,. 6,. 7) 

  // and related threads, each thread portion is calculated: ((1 + 2) + (+. 5. 4. 3 +) + (+. 6. 7)) 
Val RES = arr.par.sum 

// the reduce 
Val RES2 = arr.reduce (_ + _) 
Val RES3 = arr.reduceLeft (_ + _) 

Val = RES4 arr.par.reduce (_ + _) // which runs in parallel multithreaded 


// fold 
arr.fold (10) (_-_) 


// list which has a polymerization list 
Val List = list (List (. 1, 2, . 3), List (. 3,. 4,. 5), List (. 4,. 8,. 9)) 
list.flatten.reduce (_ + _) 
list.aggregate (0) (SUM _ + _, _ _ +). 

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

Val List L1 = (. 5,. 6,4, 7)
List L2 = Val (. 1, 2,. 3,. 4)
// and set 
L1 L2 of Union 

// intersection 
L1 L2 INTERSECT 

// set difference 
l1 diff l2

  

Guess you like

Origin www.cnblogs.com/sunnystone85/p/11357408.html