Skip to content

Instantly share code, notes, and snippets.

@andyscott
Created November 29, 2016 18:28
Show Gist options
  • Select an option

  • Save andyscott/f905be54df258677bb8401d27aa140fd to your computer and use it in GitHub Desktop.

Select an option

Save andyscott/f905be54df258677bb8401d27aa140fd to your computer and use it in GitHub Desktop.
implicit class StateTProjections[F[_]: Monad, S, A](state: StateT[F, S, A]) {
def project2_1[R2]: StateT[F, (S, R2), A] =
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s))
def project2_2[R1]: StateT[F, (R1, S), A] =
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s))
def project3_1[R2, R3]: StateT[F, (S, R2, R3), A] =
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s))
def project3_2[R1, R3]: StateT[F, (R1, S, R3), A] =
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s))
def project3_3[R1, R2]: StateT[F, (R1, R2, S), A] =
state.transformS(_._3, (r, s) ⇒ r.copy(_3 = s))
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment