collections - list.map can take a string in scala -
is str somehow implicitly converted str.charat, map function works?
val str = "abcdefghij" println(list.range(0, 10).map(str));
since str
seq of character, .map
on str
call given index.
eg.
scala> list.range(0, 10).map(str) res0: list[char] = list(a, b, c, d, e, f, g, h, i, j) // or .apply scala> list.range(0, 10).map(str.apply) res7: list[char] = list(a, b, c, d, e, f, g, h, i, j)
and str(index)
gives value index, see stringops#apply(index: int): char
scala> "my string"(4) res5: char = t
other array
, seq
example,
scala> val array = array(1, 2, 3, 4, 5) array: array[int] = array(1, 2, 3, 4, 5) scala> list.range(0, 4).map(array) res1: list[int] = list(1, 2, 3, 4) scala> val list = seq(10, 20, 30, 40, 50) list: seq[int] = list(10, 20, 30, 40, 50) scala> list.range(0, 4).map(list) res3: list[int] = list(10, 20, 30, 40)
Comments
Post a Comment