1
package hammock
2
package hi
3

4
import cats.{Eq, Show}
5
import cats.implicits._
6
import alleycats.Empty
7

8
import monocle.{Lens, Optional}
9
import monocle.macros.GenLens
10

11
case class Opts(auth: Option[Auth], headers: Map[String, String], cookies: Option[List[Cookie]])
12

13
object Opts {
14

15
  val auth: Lens[Opts, Option[Auth]] = GenLens[Opts](_.auth)
16

17
  val authOpt: Optional[Opts, Auth] = Optional[Opts, Auth] {
18 1
    _.auth
19 1
  } { auth =>
20
    {
21 1
      case opts @ Opts(Some(_), _, _) => opts.copy(auth = Some(auth))
22
      case opts                       => opts
23
    }
24
  }
25

26
  val headers: Lens[Opts, Map[String, String]] = GenLens[Opts](_.headers)
27

28
  val cookies: Lens[Opts, Option[List[Cookie]]] = GenLens[Opts](_.cookies)
29

30
  val cookiesOpt: Optional[Opts, List[Cookie]] = Optional[Opts, List[Cookie]] {
31 1
    _.cookies
32 1
  } { cookies =>
33
    {
34 1
      case opts @ Opts(_, _, Some(_)) => opts.copy(cookies = Some(cookies))
35
      case opts                       => opts
36
    }
37
  }
38

39 1
  implicit val optsEmpty = new Empty[Opts] {
40 1
    def empty = Opts(None, Map(), None)
41
  }
42

43 1
  implicit val optsEq = new Eq[Opts] {
44
    def eqv(a: Opts, b: Opts): Boolean =
45 1
      a.auth === b.auth &&
46 1
    a.headers === b.headers &&
47 1
    a.cookies === b.cookies
48
  }
49

50 1
  implicit val optsShow: Show[Opts] = Show.fromToString
51

52 1
  val empty = optsEmpty.empty
53
}

Read our documentation on viewing source code .

Loading