Skip to content

Instantly share code, notes, and snippets.

@kaja47
Last active December 20, 2015 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaja47/6096920 to your computer and use it in GitHub Desktop.
Save kaja47/6096920 to your computer and use it in GitHub Desktop.
You almost can do this in PHP, almost.
<?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];
});
// 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)
@v6ak
Copy link

v6ak commented Jul 28, 2013

I think the Scala example is wrong, it should probably be:

val usersWhoCommentedOnTheirVisiblePosts = for {
  user <- allUsers
  post <- user.posts
  comm <- post.comments
  if comm.author == comm.author // dolble "="
  // move yielf out of these brackets
} yield (user, post, comm);
// There was an extra bracket on line 9.

@kaja47
Copy link
Author

kaja47 commented Jul 28, 2013

Real men don't test their code. Really real men don't even compile their code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment