Created
November 30, 2016 06:21
-
-
Save andyscott/ccd12efc1e97243480807b90d7521f22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object StateTExtras { | |
// this is your brain, on drugs | |
implicit class StateTTupler[F[_]: Monad, S, A](state: StateT[F, S, A]) { | |
def tupled2_1[R2]: StateT[F, (S, R2), A] = | |
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s)) | |
def tupled2_2[R1]: StateT[F, (R1, S), A] = | |
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s)) | |
def tupled3_1[R2, R3]: StateT[F, (S, R2, R3), A] = | |
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s)) | |
def tupled3_2[R1, R3]: StateT[F, (R1, S, R3), A] = | |
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s)) | |
def tupled3_3[R1, R2]: StateT[F, (R1, R2, S), A] = | |
state.transformS(_._3, (r, s) ⇒ r.copy(_3 = s)) | |
def tupled4_1[R2, R3, R4]: StateT[F, (S, R2, R3, R4), A] = | |
state.transformS(_._1, (r, s) ⇒ r.copy(_1 = s)) | |
def tupled4_2[R1, R3, R4]: StateT[F, (R1, S, R3, R4), A] = | |
state.transformS(_._2, (r, s) ⇒ r.copy(_2 = s)) | |
def tupled4_3[R1, R2, R4]: StateT[F, (R1, R2, S, R4), A] = | |
state.transformS(_._3, (r, s) ⇒ r.copy(_3 = s)) | |
def tupled4_4[R1, R2, R3]: StateT[F, (R1, R2, R3, S), A] = | |
state.transformS(_._4, (r, s) ⇒ r.copy(_4 = s)) | |
} | |
def tupled2_1[S1, S2]: State[S1, ?] ~> State[(S1, S2), ?] = | |
λ[State[S1, ?] ~> State[(S1, S2), ?]](_.tupled2_1) | |
def tupled2_2[S1, S2]: State[S2, ?] ~> State[(S1, S2), ?] = | |
λ[State[S2, ?] ~> State[(S1, S2), ?]](_.tupled2_2) | |
def tupled3_1[S1, S2, S3]: State[S1, ?] ~> State[(S1, S2, S3), ?] = | |
λ[State[S1, ?] ~> State[(S1, S2, S3), ?]](_.tupled3_1) | |
def tupled3_2[S1, S2, S3]: State[S2, ?] ~> State[(S1, S2, S3), ?] = | |
λ[State[S2, ?] ~> State[(S1, S2, S3), ?]](_.tupled3_2) | |
def tupled3_3[S1, S2, S3]: State[S3, ?] ~> State[(S1, S2, S3), ?] = | |
λ[State[S3, ?] ~> State[(S1, S2, S3), ?]](_.tupled3_3) | |
def tupled4_1[S1, S2, S3, S4]: State[S1, ?] ~> State[(S1, S2, S3, S4), ?] = | |
λ[State[S1, ?] ~> State[(S1, S2, S3, S4), ?]](_.tupled4_1) | |
def tupled4_2[S1, S2, S3, S4]: State[S2, ?] ~> State[(S1, S2, S3, S4), ?] = | |
λ[State[S2, ?] ~> State[(S1, S2, S3, S4), ?]](_.tupled4_2) | |
def tupled4_3[S1, S2, S3, S4]: State[S3, ?] ~> State[(S1, S2, S3, S4), ?] = | |
λ[State[S3, ?] ~> State[(S1, S2, S3, S4), ?]](_.tupled4_3) | |
def tupled4_4[S1, S2, S3, S4]: State[S4, ?] ~> State[(S1, S2, S3, S4), ?] = | |
λ[State[S4, ?] ~> State[(S1, S2, S3, S4), ?]](_.tupled4_4) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment