Last active
December 20, 2015 07:58
-
-
Save kaja47/6096920 to your computer and use it in GitHub Desktop.
You almost can do this in PHP, almost.
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
| <?php | |
| // generators are weaker than monads and this is therefore not possible | |
| // CPS transformation to state machines sucks balls | |
| $usersWhoCommentedOnTheirPosts = run($seqMonad, function () { | |
| $user = (yield allUsers()); | |
| $post = (yield $user->posts); | |
| $comm = (yield $post->comments); | |
| if ($comm->author === $comm->author) | |
| yield [$user, $post, $comm]; | |
| }); |
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
| // same thing in Scala look pretty much the same | |
| val usersWhoCommentedOnTheirVisiblePosts = for { | |
| user <- allUsers | |
| post <- user.posts | |
| comm <- post.comments | |
| if comm.author == comm.author | |
| } yield (user, post, comm) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Real men don't test their code. Really real men don't even compile their code.