Scala: Option, Some and the ArrowAssoc operator -


i trying analyze following piece of scala code:

import java.nio.file._ import scala.some  abstract class mycustomdirectoryiterator[t](path:path,somenumber:int, anothernum:int) extends iterator[t] {  def getcustomiterator(mypath:path):option[(directorystream[path],                                                  iterator[path])] = try {   //we directory stream            val str = files.newdirectorystream(mypath)     //then iterator out of stream     val iter = str.iterator()     some((str -> iter))   } catch {     case de:directoryiteratorexception =>       printstacktrace(de.getmessage)       none    } 

how interpert piece of code: some((str -> iter)) yes, returning value of type:

option[(directorystream[path], iterator[path])] 

the -> operator is, best of understanding, arrowassoc scala.predef package.

implicit final class arrowassoc[a] extends anyval 

but still not understand -> thing doing give me return value of type:

option[(directorystream[path], iterator[path])] 

can scala experts out here throw more light on this? there way write "some(..)" thing in more readable way? understand role played some, though.

the -> operator creates tuple:

scala> 1 -> "one" res0: (int, string) = (1,one) 

which equivalent to

scala> (1, "one") res1: (int, string) = (1,one) 

i going add source code, reactormonk has got there first ;-)

the -> method made available on object via implicit arrowassoc class. calling on object of type a, passing parameter of type b, creates tuple2[a, b].


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -