scala - Iterable with two elements? -


we have option iterable on 0 or 1 elements.

i have such thing 2 elements. best have

array(foo, bar).map{...}, while is:

(foo, bar).map{...} 

(such scala recognized there 2 elements in iterable).

does such construction exist in standard library?

edit: solution create map method:

def map(a:foo) = {...}  val (mappedfoo, mappedbar) = (map(foo), map(bar)) 

if want map on tuples of same type, simple version is:

implicit class dupleops[t](t: (t,t)) {   def map[b](f : t => b) = (f(t._1), f(t._2)) } 

then can following:

val t = (0,1) val (x,y) = t.map( _ +1)  // x = 1, y = 2 

there's no specific type in scala standard library mapping on 2 elements.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -