Я не думаю, что в Scala есть что-то особенное или сложное в фигурных скобках. Чтобы справиться с кажущимся сложным использованием их в Scala, просто сохраните пару простых вещей:
Давайте объясним несколько примеров в трех предыдущих правила:
val tupleList = List[(String, String)]()
// doesn't compile, violates case clause requirement
val filtered = tupleList.takeWhile( case (s1, s2) => s1 == s2 )
// block of code as a partial function and parentheses omission,
// i.e. tupleList.takeWhile({ case (s1, s2) => s1 == s2 })
val filtered = tupleList.takeWhile{ case (s1, s2) => s1 == s2 }
// curly braces omission, i.e. List(1, 2, 3).reduceLeft({_+_})
List(1, 2, 3).reduceLeft(_+_)
// parentheses omission, i.e. List(1, 2, 3).reduceLeft({_+_})
List(1, 2, 3).reduceLeft{_+_}
// not both though it compiles, because meaning totally changes due to precedence
List(1, 2, 3).reduceLeft _+_ // res1: String => String = <function1>
// curly braces omission, i.e. List(1, 2, 3).foldLeft(0)({_ + _})
List(1, 2, 3).foldLeft(0)(_ + _)
// parentheses omission, i.e. List(1, 2, 3).foldLeft(0)({_ + _})
List(1, 2, 3).foldLeft(0){_ + _}
// block of code and parentheses omission
List(1, 2, 3).foldLeft {0} {_ + _}
// not both though it compiles, because meaning totally changes due to precedence
List(1, 2, 3).foldLeft(0) _ + _
// error: ';' expected but integer literal found.
List(1, 2, 3).foldLeft 0 (_ + _)
def foo(f: Int => Unit) = { println("Entering foo"); f(4) }
// block of code that just evaluates to a value of a function, and parentheses omission
// i.e. foo({ println("Hey"); x => println(x) })
foo { println("Hey"); x => println(x) }
// parentheses omission, i.e. f({x})
def f(x: Int): Int = f {x}
// error: missing arguments for method f
def f(x: Int): Int = f x
Мы могли бы использовать mapply
и создать последовательность между двумя столбцами
unlist(mapply(`:`, m$V1, m$V2))
#[1] 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37..
#[29] 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65..
#[57] 76 77 78 79 80 81 82 83 84 32 33 34 35 36 37 38 39 40..
#[85] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68..
#[113] 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96..
#[141] 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 ..
#[169] 88 89 90 91 92 93 94 95 96 97 98 99 100 101
Вот вариант с использованием pmap
library(purrr)
library(dplyr)
set_names(m, c('from', 'to')) %>%
pmap(., seq) %>%
unlist
<час> Или с использованием Map
из base R
unlist(do.call(Map, c(f = `:`, m)))