Skip to content

Commit

Permalink
Close #87 - Add Writer constructor for (W, A)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lee committed Sep 29, 2019
1 parent 75b66b2 commit 998c359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/scala/just/fp/package.scala
Expand Up @@ -11,6 +11,8 @@ package object fp extends IdInstance {
type Writer[L, V] = WriterT[Id, L, V]

object Writer {
def apply[W, A](w: W, a: A): WriterT[Id, W, A] = WriterT[Id, W, A]((w, a))
def apply[W, A](w: W, a: A): Writer[W, A] = Writer.writer((w, a))

def writer[W, A](wa: (W, A)): Writer[W, A] = WriterT[Id, W, A](wa)
}
}
13 changes: 13 additions & 0 deletions src/test/scala/just/fp/WriterTSpec.scala
Expand Up @@ -16,6 +16,7 @@ object WriterTSpec extends Properties {
, property("testWriterFunctorLaws", WriterFunctorLaws.laws)
, property("testWriterApplicativeLaws", WriterApplicativeLaws.laws)
, property("testWriterMonadLaws", WriterMonadLaws.laws)
, property("test Writer(w, a) should be equal to Writer.writer((w, a))", testWriterApplyAndWriter)
)

object WriterTFunctorLaws {
Expand Down Expand Up @@ -98,4 +99,16 @@ object WriterTSpec extends Properties {
, Gens.genAToMonadA(Gens.genIntToInt)
)
}

def testWriterApplyAndWriter: Property = for {
w <- Gens.genUnicodeString.log("w")
a <- Gens.genIntFromMinToMax.log("a")
wa = (w, a)
} yield {
val writer1 = Writer.writer(wa)
val writer2 = Writer(w, a)

import just.fp.syntax._
Result.diffNamed("=== Not Equal ===", writer1, writer2)(_ === _)
}
}

0 comments on commit 998c359

Please sign in to comment.