Skip to content

Commit

Permalink
Merge pull request #90 from Kevin-Lee/task/89/add-writer-syntax
Browse files Browse the repository at this point in the history
Close #89 - Add writer syntax
  • Loading branch information
kevin-lee authored Oct 2, 2019
2 parents f5b4c7d + 4417ab5 commit 4244972
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/scala/just/fp/syntax/WriterSyntax.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package just.fp.syntax

import just.fp.Writer

import scala.language.implicitConversions

/**
* @author Kevin Lee
* @since 2019-10-02
*/
object WriterOps {
final class ToWriter[A](val a: A) extends AnyVal {
def writer[W](w: W): Writer[W, A] = Writer(w, a)
}
}

trait WriterSyntax {
import WriterOps._

@SuppressWarnings(Array("org.wartremover.warts.ImplicitConversion"))
implicit final def toWriter[A](a: A): ToWriter[A] = new ToWriter(a)
}
1 change: 1 addition & 0 deletions src/main/scala/just/fp/syntax/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ package object syntax
with OptionSyntax
with EitherSyntax
with SemiGroupSyntax
with WriterSyntax
28 changes: 28 additions & 0 deletions src/test/scala/just/fp/syntax/WriterSyntaxSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package just.fp.syntax

import hedgehog._
import hedgehog.runner._

import just.fp.Gens

/**
* @author Kevin Lee
* @since 2019-10-02
*/
object WriterSyntaxSpec extends Properties {
override def tests: List[Test] = List(
property("test value.writer(w) syntax", testValueWriter)
)

def testValueWriter: Property = for {
a <- Gens.genIntFromMinToMax.log("a")
w <- Gens.genUnicodeString.log("w")
} yield {
import just.fp._

val expected = Writer(w, a)
val actual = a.writer(w)

actual ==== expected
}
}

0 comments on commit 4244972

Please sign in to comment.