楼主: ReneeBK
1180 8

Scala:Tutorials about the Scala Programming Language [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49407 个
通用积分
51.8104
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

本帖隐藏的内容

http://alvinalexander.com/scala


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Programming Tutorials Language Tutorial Program about

本帖被以下文库推荐

沙发
ReneeBK 发表于 2017-1-20 01:23:55 |只看作者 |坛友微信交流群
  1. Scala code to read a text file to an Array (or Seq)
  2. As a quick note, I use code like this read a text file into an Array, List, or Seq using Scala:

  3. def readFile(filename: String): Seq[String] = {
  4.     val bufferedSource = io.Source.fromFile(filename)
  5.     val lines = (for (line <- bufferedSource.getLines()) yield line).toList
  6.     bufferedSource.close
  7.     lines
  8. }
复制代码

使用道具

藤椅
ReneeBK 发表于 2017-1-20 01:24:54 |只看作者 |坛友微信交流群
  1. How to shuffle (randomize) a list in Scala
  2. As a quick note today, to shuffle a list in Scala, use this technique:

  3. scala.util.Random.shuffle(List(1,2,3,4))
复制代码

使用道具

板凳
ReneeBK 发表于 2017-1-20 01:25:45 |只看作者 |坛友微信交流群
  1. How to use ScalaCheck in the SBT REPL (command line)
  2. If you add ScalaCheck to an SBT project like this:

  3. libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"
  4. it’s only available in the SBT “test” scope. This means that when you start a Scala REPL session inside of SBT with its console command, the ScalaCheck library won’t be available in that scope.

  5. To use ScalaCheck with the SBT console (REPL), don’t use its console command — use test:console instead. A complete example looks like this:

  6. $ sbt

  7. > test:console

  8. scala> import org.scalacheck.Gen.choose
  9. Note that after you type test:console your project may be compiled, so that step may take a few moments.

  10. In summary, use SBT’s console command to start a “normal” Scala REPL inside SBT, and use test:console to start a REPL that you can run tests inside of. (Note that this same advice also applies to using ScalaTest or
复制代码

使用道具

报纸
ReneeBK 发表于 2017-1-20 01:28:00 |只看作者 |坛友微信交流群
  1. Sealed classes are described in 'Programming in Scala', but sealed traits are not. Where can I find more information about a sealed trait?

  2. I would like to know, if a sealed trait is the same as a sealed class? Or, if not, what are the differences? When is it a good idea to use a sealed trait (and when not)?
  3. A sealed trait can be extended only in the same file as its declaration.

  4. They are often used to provide an alternative to enums. Since they can be only extended in a single file, the compiler knows every possible subtypes and can reason about it.

  5. For instance with the declaration:

  6. sealed trait Answer
  7. case object Yes extends Answer
  8. case object No extends Answer
  9. The compiler will emit a warning if a match is not exhaustive:

  10. scala> val x: Answer = Yes
  11. x: Answer = Yes

  12. scala> x match {
  13.      |   case No => println("No")
  14.      | }
  15. <console>:12: warning: match is not exhaustive!
  16. missing combination            Yes
  17. So you should use sealed traits (or sealed abstract class) if the number of possible subtypes is finite and known in advance. For more examples you can have a look at list and option implementations
复制代码

使用道具

地板
auirzxp 学生认证  发表于 2017-1-20 01:42:50 |只看作者 |坛友微信交流群

使用道具

7
这里的黎明 发表于 2017-1-20 06:03:26 |只看作者 |坛友微信交流群

使用道具

8
neuroexplorer 发表于 2017-1-20 07:47:16 |只看作者 |坛友微信交流群
Thanks!!!!!!

使用道具

9
franky_sas 发表于 2017-1-20 07:57:44 |只看作者 |坛友微信交流群

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-26 00:42