Skip to content

Instantly share code, notes, and snippets.

@MateuszKubuszok
Last active October 14, 2021 09:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MateuszKubuszok/a80503b28f289f08f2f6c6c70871e8d3 to your computer and use it in GitHub Desktop.
Save MateuszKubuszok/a80503b28f289f08f2f6c6c70871e8d3 to your computer and use it in GitHub Desktop.
Useful Ammonite snippets

Useful Ammonite snippets

All of these can be figured out by looking at ammonite.io and at libraries pages, but to make things faster for myself I written it down (I don't always want to search through Ammonite history nor pollute my ~/.ammonite/predef.sc).

For convenience, next to library there is badge with the newest version and next to one liners for Ammonite for specific version is link to releases - it let you update to newest version without goolging or checking project's site.

(ToC generated using Markdown TOC generate)

Ammonite for specific Scala version

Newest releases.

2.10

Last release of 2.10 (1.0.3)

[ -f /tmp/ammonite-2.10/amm ] || (mkdir /tmp/ammonite-2.10 -p && curl -L https://github.com/lihaoyi/Ammonite/releases/download/1.0.3/2.10-1.0.3 > /tmp/ammonite-2.10/amm && chmod +x /tmp/ammonite-2.10/amm) && /tmp/ammonite-2.10/amm

2.11

Last release of 2.11 (1.6.7)

[ -f /tmp/ammonite-2.11/amm ] || (mkdir /tmp/ammonite-2.11 -p && curl -L https://github.com/lihaoyi/Ammonite/releases/download/1.6.7/2.11-1.6.7 > /tmp/ammonite-2.11/amm && chmod +x /tmp/ammonite-2.11/amm) && /tmp/ammonite-2.11/amm

2.12

[ -f /tmp/ammonite-2.12/amm ] || (mkdir /tmp/ammonite-2.12 -p && curl -L https://github.com/lihaoyi/Ammonite/releases/download/2.1.4/2.12-2.1.4 > /tmp/ammonite-2.12/amm && chmod +x /tmp/ammonite-2.12/amm) && /tmp/ammonite-2.12/amm

2.13

[ -f /tmp/ammonite-2.13/amm ] || (mkdir /tmp/ammonite-2.13 -p && curl -L https://github.com/lihaoyi/Ammonite/releases/download/2.1.4/2.13-2.1.4 > /tmp/ammonite-2.13/amm && chmod +x /tmp/ammonite-2.13/amm) && /tmp/ammonite-2.13/amm

Generate Ammonite import format from sbt/coursier import format

implicit class PrintImport(deps: coursierapi.Dependency) {
  def forAmmonite(mock: Any): Unit = println(s"import $$ivy.`${deps.getModule.getOrganization}:${deps.getModule.getName}:${deps.getVersion}`")
  def fetch(mock: Any): Unit = interp.load.ivy(deps)
}

Copy-paste sbt dependency into Ammonite, add forAmmonite () and run it

@ "org.typelevel" %% "cats-core" % "2.1.1" forAmmonite ()
import $ivy.`org.typelevel:cats-core_2.13:2.1.1`

then copy-paste output of forAmmnite () in order to import it or share with others or

@ "org.typelevel" %% "cats-core" % "2.1.1" fetch ()

to fetch dependencies and make them available in REPL.

Standard library utils

import scala.util._, scala.concurrent._, scala.concurrent.duration._

Not use together with monix.execution.Scheduler

import scala.concurrent.ExecutionContext.Implicits.global

2.13-only

import scala.util.chaining._

Set compiler flags

Enable macro annotations

2.13-only, 2.12 needs Macro paradise

interp.configureCompiler(_.settings.YmacroAnnotations.value = true)

Log implicits

interp.configureCompiler(_.settings.XlogImplicits.value = true)

Partial unification

Build-in in 2.13, only needed in 2.12

interp.configureCompiler(_.settings.YpartialUnification.value = true)

Load compiler plugins

Maven Central

import $plugin.$ivy.`org.typelevel:kind-projector_2.13.2:0.11.0`

Maven Central

import $plugin.$ivy.`com.olegpy::better-monadic-for:0.3.1`

2.13 replaced it with Ymacro-annotation compiler flag

Maven Central

import $plugin.$ivy.`org.scalamacros:paradise_2.12.11:2.1.1`

Maven Central

import $plugin.$ivy.`io.tryp:splain_2.13.2:0.5.6`

Import libraries

Maven Central

import $ivy.`org.typelevel::cats-core:2.1.0`, cats._, cats.data._, cats.implicits._

Maven Central

import $ivy.`org.typelevel::cats-effect:2.1.3`, cats.effect._

Maven Central

import `org.typelevel::kittens:2.1.0`, cats.derived.auto._

Maven Central

import $ivy.`io.circe::circe-generic:0.13.0`, io.circe._, io.circe.generic.auto._
import $ivy.`io.circe::circe-parser:0.13.0`, io.circe.parser._
import $ivy.`io.circe::circe-optics:0.13.0`, io.circe.optics.JsonPath._

Maven Central

import $ivy.`com.beachape::enumeratum:1.6.0`, enumeratum._
import $ivy.`com.beachape::enumeratum-circe:1.6.0`, enumeratum._

Maven Central

import $ivy.`co.fs2::fs2-core:2.3.0`, fs2._
import $ivy.`co.fs2::fs2-io:2.3.0`, fs2._

Maven Central

import $ivy.`io.monix::monix:3.2.1`, monix.eval._, monix.execution._
import monix.execution.Scheduler.Implicits.global

Maven Central

import $ivy.`com.github.pureconfig::pureconfig:0.12.3`, pureconfig._

Maven Central

import $ivy.`com.chuusai::shapeless:2.3.3`, shapeless._

Maven Central

import $ivy.`io.scalaland::chimney:0.5.2`, io.scalaland.chimney.dsl._
import $ivy.`io.scalaland::chimney-cats:0.5.2`, io.scalaland.chimney.cats._

Maven Central

interp.configureCompiler(_.settings.YmacroAnnotations.value = true)
import $ivy.`io.scalaland::catnip:1.0.0`, io.scalaland.catnip._, cats._, cats.implicits._, alleycats.std.all._

Maven Central

import $ivy.`io.scalaland::enumz:1.0.0`, io.scalaland.enumz.Enum
@MateuszKubuszok
Copy link
Author

MateuszKubuszok commented May 25, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment