Skip to content

Instantly share code, notes, and snippets.

@psilospore
Last active September 25, 2018 19:40
Show Gist options
  • Save psilospore/ba8f1c44893408745fa8d7f6747ce4a9 to your computer and use it in GitHub Desktop.
Save psilospore/ba8f1c44893408745fa8d7f6747ce4a9 to your computer and use it in GitHub Desktop.
Scala and IntelliJ Bag'o'Tricks

Bag O Tricks

Scala

Set up build.sbt with the following:

//TODO add cats
scalaVersion := "2.12.4"

libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.2.18"

libraryDependencies += "org.scalaz" %% "scalaz-concurrent" % "7.2.23"

libraryDependencies += "org.tpolecat" %% "doobie-core" % "0.5.3"

libraryDependencies +=  "org.scalaj" %% "scalaj-http" % "2.4.0"

initialCommands += "import scalaz._, Scalaz._"

For comprehension with Option and List

I could probably use a similar technique on other types

val some = Some(1)
val list = List(2,3,4)
for {
  s <- some
  x <- list //expected option
} yield {...}

for {
  s <- some.toSeq
  x <- list
} yield {...} //works!

SBT

Exclude a file in your app

excludeFilter in unmanagedSources := "PsilosporeTest.scala"

I do this when I want to write short scripts but want all my imports available

Ignore unused imports

set scalacOptions in <projectname> -= "-Ywarn-unused:imports"

I disable this when I'm actively developing while but reenable right before I commit

IntelliJ

Search Command

CMD + Shift + A Probably the most useful command. I don't have to bother with memorizing commands. I can search refactor, rename, do this do that blah blah

Use named arguments for current and subsequent arguments

Cursor on first argument + Search Command + Use named arguments for current and subsequent arguments Not a big fan of long list of arguments.

case class Cat(name: String, age: Long, owner: Person)

Cat("tabby", 6, Person("Syed"))
//This will change to

Cat(
  name = "tabby",
  age = 6,
  owner = Person("Syed")
)

## Others

### Scalafmt

Default setting looks like butt. Don't use it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment