Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download

Jupyter notebook scala.ipynb

Project: compute8-us
Views: 312
Kernel: Scala 2.11

Scala 2.11 in SMC

println("hi")
hi
def filter(xs: List[Int], p: Int => Boolean): List[Int] = if (xs.isEmpty) xs else if (p(xs.head)) xs.head :: filter(xs.tail, p) else filter(xs.tail, p) def modN(n: Int)(x: Int) = ((x % n) == 0) val nums = List(1, 2, 3, 4, 5, 6, 7, 8) println(filter(nums, modN(2))) println(filter(nums, modN(3)))
List(2, 4, 6, 8) List(3, 6)
defined function filter defined function modN nums: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8)
def dup[T](x: T, n: Int): List[T] = { if (n == 0) Nil else x :: dup(x, n - 1) } println(dup[Int](3, 4)) println(dup("three", 3))
List(3, 3, 3, 3) List(three, three, three)
defined function dup