implicit def optionInjection[A, B]()

in bijection-core/src/main/scala-2.13+/com/twitter/bijection/CollectionInjections.scala [24:39]


  implicit def optionInjection[A, B](implicit
      inj: Injection[A, B]
  ): Injection[Option[A], Option[B]] =
    new AbstractInjection[Option[A], Option[B]] {
      def apply(a: Option[A]) = a.map(inj)
      def invert(b: Option[B]) = {
        if (b.isEmpty) {
          // This is the inverse of a == None
          Success(None)
        } else {
          val optA = inj.invert(b.get)
          // If it is not None, then convert to Success(Some(_))
          optA.map { Some(_) }
        }
      }
    }