Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OptionT.none, resolving #935 #946

Merged
merged 3 commits into from
Apr 1, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
@@ -94,6 +94,9 @@ object OptionT extends OptionTInstances {
def pure[F[_], A](a: A)(implicit F: Applicative[F]): OptionT[F, A] =
OptionT(F.pure(Some(a)))

def none[F[_], A](implicit F: Applicative[F]) : OptionT[F, A] =
OptionT(F.pure(None))

/**
* Transforms an `Option` into an `OptionT`, lifted into the specified `Applicative`.
*
4 changes: 4 additions & 0 deletions tests/src/test/scala/cats/tests/OptionTTests.scala
Original file line number Diff line number Diff line change
@@ -134,6 +134,10 @@ class OptionTTests extends CatsSuite {
OptionT[Xor[String, ?], Int](xor).show should === ("Xor.Right(Some(1))")
}

test("none") {
OptionT.none[List,Int] should === (OptionT[List,Int](List(None)))
}

test("implicit Show[OptionT] instance and explicit show method are consistent") {
forAll { optionT: OptionT[List, Int] =>
optionT.show should === (implicitly[Show[OptionT[List, Int]]].show(optionT))