LoginSignup
12
10

More than 5 years have passed since last update.

import scalaz._, Scalaz._をやめる

Last updated at Posted at 2016-08-24

Scalaz便利ですが、import scalaz._, Scalaz._ するとIntelliJが重くなってきます。使うモジュールに合わせてimportしましょう。

だいたい3通り(たぶん)

Scalazが提供する型を使う => import scalaz.Foo

import scalaz.\/

def search(s: String): String \/ Seq[Foo] = ???

\/.fromTryCatchNonFatal(aSafeFunction("foo")) // \/-("bar")
\/.fromTryCatchNonFatal( throw new Exception("noo") ) // -\/(java.lang.Exception: noo)

import scalaz.NonEmptyList

NonEmptyList(1, 2, 3) // NonEmpty[1,2,3]

Scala標準の型を返すインスタンス、関数を使う => import scalaz.std.foo._

import scalaz.std.option._

none[Int] // None: Option[Int]

import scalaz.std.boolean._

nand(false, true) // true: Boolean

メソッドを生やす

  • Scala標準の型にメソッドを生やす => import scalaz.syntax.std.foo._
  • Scalazの型にメソッドを生やす => import scalaz.syntax.foo._
import scalaz.syntax.std.boolean._

true.option("success") // Some(success)
false either 1 or "boo" // -\/(boo): \/[String,Int]

import scalaz.syntax.either._

1.right[String] // \/-(1): \/[String,Int]

import scalaz.{ NonEmptyList, OptionT }
import scalaz.syntax.monad._

NonEmptyList(1,2,3).liftM[OptionT] // OptionT(NonEmpty[Some(1),Some(2),Some(3)])
12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10