Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some interesting combinators that build on alternation over sequences #82

Merged
merged 10 commits into from
Apr 28, 2015
Merged

Add some interesting combinators that build on alternation over sequences #82

merged 10 commits into from
Apr 28, 2015

Conversation

sharplet
Copy link
Collaborator

Let me preface this by saying that may agenda here was ultimately to build the
anyOf() combinator for my own purposes — I don't know if this is the kind of
thing you want to be included in Madness core! But along the way I discovered
some interesting and fun things, and if any of them fit then feel free to
cherry-pick just those. I've got what I was looking for. 😇

A brief summary:

  • inject(): A name that I came up with for monadic return over parsers.
    (I'm not super attached to the name.)
  • oneOf(): Kinda looks like mconcat over parsers (!), but limited to literals.
    (I'm guessing that mconcat wouldn't really be possible because of the
    trouble with function types in generic constraints, and the general lack of
    higher-kinded types.)
  • anyOf(): That's what I came here for. I'm planning to use this one to parse
    abbreviated short option strings, e.g., -la => [-l, -a] // "any of" l or a.
    It's interesting, but up to you whether it's suitable for inclusion in Madness.
  • allOf(): Logical addition to go alongside anyOf(). Basically a greedier
    version that pulls out all the matches from the set of literals.

Thanks for the great library, this was a lot of fun! Looking forward to your
feedback. 😊

@robrix
Copy link
Owner

robrix commented Apr 27, 2015

Whoa, fun! Thanks for the PR.

none() resolves #35, so thanks for that too 😄

@@ -159,6 +159,7 @@
D4FC47B21A37E47C00D23A6F /* Products */,
);
sourceTree = "<group>";
usesTabs = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know why Xcode never enables this for me.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a project-level setting. If you click on the actual Xcode project in the navigator, then go over to the utilities sidebar on the right, there's an option to set tabs/spaces at the project level, overriding whatever your defaults are in Xcode's preferences.
screen shot 2015-04-27 at 7 25 30 pm

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, what I meant was that as far as I knew this was already enabled.

@robrix
Copy link
Owner

robrix commented Apr 27, 2015

Basically all of these are awesome and you are awesome and I am very grateful 🙇

Just the one question, really; this is golden ⭐

`inject` unfortunately is a little confusing because of the connection
with reduce/inject in Smalltalk/Ruby.

Also `pure` is better.
@sharplet
Copy link
Collaborator Author

Thanks for the lovely comments @robrix, glad you liked it! Took me quite a lot of wading through complex index-munging logic beforeI realised that I could use flatMap, and magically everything just got simpler. 😮

Ready when you are.

@sharplet
Copy link
Collaborator Author

Oh btw, something else I considered was adding <^> to wrap >>- + pure(). But that could be another PR.

@robrix
Copy link
Owner

robrix commented Apr 28, 2015

<^> in another PR sounds great!

robrix added a commit that referenced this pull request Apr 28, 2015
Add some interesting combinators that build on alternation over sequences
@robrix robrix merged commit 2c15a36 into robrix:master Apr 28, 2015
@robrix robrix self-assigned this Apr 28, 2015
@robrix
Copy link
Owner

robrix commented Apr 28, 2015

🎉

I’ve added you as a collaborator @sharplet. Same as on Set, PRs & review preferred for nontrivial stuff, but you can tag releases and review and such now too if you like.

@robrix
Copy link
Owner

robrix commented Apr 28, 2015

Also: ⭐ for your branch name.

@sharplet sharplet deleted the more-of-madness branch April 28, 2015 01:15
@sharplet
Copy link
Collaborator Author

😁

@robrix robrix mentioned this pull request May 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants