Finding character in 2 dimensional scala list -


so might not best way tackle initial thought expression. have list like

list(list('a','b','c'),list('d','e','f'),list('h','i','j')) 

i find row , column character, 'e'.

def findchar(letter: char, list: list[list[char]]): (int, int) =   {     r <- (0 until list.length)     c <- (0 until list(r).length)     if list(r)(c) == letter   } yield (r, c) 

if there more elegant way i'm ears understand what's wrong this. error compiler gives me here

type mismatch;  found   : scala.collection.immutable.indexedseq[(int, int)]  required: (int, int) 

on line assigning r. seems complaining iterator doesn't match return type don't quite understand why or ...

for other ear, question duplicates

how capture inner matched value in indexwhere vector expression?

scala> list(list('a','b','c'),list('d','e','f'),list('h','i','j')) res0: list[list[char]] = list(list(a, b, c), list(d, e, f), list(h, i, j))  scala> .map(_ indexof 'e').zipwithindex.find(_._1 > -1) res1: option[(int, int)] = some((1,1)) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -