Created
November 29, 2016 18:28
-
-
Save andyscott/f905be54df258677bb8401d27aa140fd 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
| 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