Scala Tips

Date Tags Scala
content
    • foreach
    val xs = List("date", "since", "other1", "other2")
    
    xs.foreach { str =>
    
        str match {
            case "date"  => println("Match Date")
            case "since" => println("Match Since")
            case unknow  => println("Others")
        } 
    
        println("Put your post step here")
    }
    

    注意:如果要使用一段代码作为foreach()的参 …

    more ...


    Closure

    Date Tags Scala

    什么是闭包?

    引用至少一个自由变量的函数称为闭包。

    闭包是一个函数,可纯函数或非纯函数,可有名字或匿名,但重要的是 …

    more ...

    Case Class vs Class

    Date Tags Scala

    定义

    • class的定义:
    class BankAccount {
      def deposit(amount: Int): Unit = {
        if (amount > 0) balance = balance + amount
      }
    
    • case class的定义:
    case class Note(name: String, duration: String, octave: Int)
    
    • 创建BankAccountNote的实例:
    val aliceAccount = new BankAccount()
    val c3 = Note("C", "Quarter …
    more ...



    Scala

    Date Tags Scala

    前言

    Functional Programming

    Part-1: Elements of Functional Programming

    什么是函数式编程?(Functional Programming) 函数式编程是一种仅使用纯函数(pure functions)和不可变值(immutable values)编写软件应用程序 …

    more ...