Skip to content

Instantly share code, notes, and snippets.

@JavierCane
Created November 22, 2017 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JavierCane/57985c072026b36bcce0f3888164c2f5 to your computer and use it in GitHub Desktop.
Save JavierCane/57985c072026b36bcce0f3888164c2f5 to your computer and use it in GitHub Desktop.
Scala companion object example for the CodelyTV Pro Scala course πŸ‘‰ https://pro.codely.tv/
package tv.codely.scala_intro_examples.lesson_09_oop
import scala.util.Random
object NumberWithCompanionObject {
def apply(value: String): NumberWithCompanionObject = NumberWithCompanionObject(value = value.toInt)
def random: NumberWithCompanionObject = NumberWithCompanionObject(value = Random.nextInt())
}
final case class NumberWithCompanionObject(value: Int) {
val plusOne: NumberWithCompanionObject = copy(value = value + 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment