Skip to content

Commit

Permalink
Merge pull request #97 from road21/option-either-functions
Browse files Browse the repository at this point in the history
add option/either functions
  • Loading branch information
Odomontois authored Jan 9, 2020
2 parents 143788c + a4564cf commit 5c66362
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions optics/core/src/main/scala/tofu/optics/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tofu.optics

import cats.Apply
import cats.syntax.apply._
import cats.syntax.either._
import cats.instances.all._
import alleycats.std.map._

Expand Down Expand Up @@ -47,4 +48,12 @@ object functions {

def everyTuple4[A, B]: PItems[(A, A, A, A), (B, B, B, B), A, B] =
PItems[(A, A, A, A), A, B](implicit A => (s, f) => (f(s._1), f(s._2), f(s._3), f(s._4)).tupled)

def right[A, B]: Subset[Either[A, B], B] = Subset[Either[A, B]](_.toOption)(_.asRight)

def left[A, B]: Subset[Either[A, B], A] = Subset[Either[A, B]](_.fold(Some(_), _ => None))(_.asLeft)

def some[A]: Subset[Option[A], A] = Subset[Option[A]](identity)(Some(_))

def none[A]: Subset[Option[A], Unit] = Subset[Option[A]](_ => Some(()))(_ => None)
}

0 comments on commit 5c66362

Please sign in to comment.