-
-
Notifications
You must be signed in to change notification settings - Fork 202
/
Possible.scala
59 lines (49 loc) · 1.88 KB
/
Possible.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package monocle.function
import monocle.{Iso, Optional}
import scala.util.Try
import cats.data.Validated
/** Typeclass that defines an [[Optional]] from a monomorphic container `S` to a possible value `A`. There must be at
* most one `A` in `S`.
* @tparam S
* source of the [[Optional]]
* @tparam A
* target of the [[Optional]], `A` is supposed to be unique for a given `S`
*/
@deprecated("no replacement", since = "3.0.0-M1")
abstract class Possible[S, A] extends Serializable {
def possible: Optional[S, A]
}
trait PossibleFunctions {
@deprecated("no replacement", since = "3.0.0-M1")
def possible[S, A](implicit ev: Possible[S, A]): Optional[S, A] = ev.possible
}
object Possible extends PossibleFunctions {
def apply[S, A](optional: Optional[S, A]): Possible[S, A] =
new Possible[S, A] {
override val possible: Optional[S, A] = optional
}
/** lift an instance of [[monocle.Optional]] using an [[Iso]] */
def fromIso[S, A, B](iso: Iso[S, A])(implicit ev: Possible[A, B]): Possible[S, B] =
Possible(iso.andThen(ev.possible))
/** *********************************************************************************************
*/
/** Std instances */
/** *********************************************************************************************
*/
implicit def optionPossible[A]: Possible[Option[A], A] =
new Possible[Option[A], A] {
def possible = monocle.std.option.some
}
implicit def eitherPossible[A, B]: Possible[Either[A, B], B] =
new Possible[Either[A, B], B] {
def possible = monocle.std.either.stdRight
}
implicit def validatedPossible[A, B]: Possible[Validated[A, B], B] =
new Possible[Validated[A, B], B] {
def possible = monocle.std.validated.success
}
implicit def tryPossible[A]: Possible[Try[A], A] =
new Possible[Try[A], A] {
def possible = monocle.std.utilTry.trySuccess
}
}