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 Applicative *>
, <*
, and Alternative <|>
operators
#66
Add Applicative *>
, <*
, and Alternative <|>
operators
#66
Conversation
Expected function type: `f a -> f a -> f a` | ||
Haskell `infixl 3` | ||
*/ | ||
infix operator <|> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration. (opening_brace)
Hmm, it seems below workaround is needed for using Argo when return curry(self.init)
<^> j <| "id"
<*> (j <| ["userinfo", "name"] <|> j <| "name") // <- needs parenthesis to work around...
<*> j <|? "email" It works better when |
@inamiy Is that a problem with the precedence of Argo's It's probably worth noting that we'll probably revisit all of these precedence settings in Swift 3. |
After looking back and simplifying my above old snippet, I found the problem was only in between let d1: Decoded<String> = j <| ["userinfo", "name"]
let d2: Decoded<String> = j <| "name"
return curry(self.init)
<^> j <| "id"
<*> (d1 <|> d2) // <- parenthesis is still required
<*> j <|? "email" Because of This will be a breaking change, so it sounds good to revisit all precedence settings before Swift 3 ;) |
Cool, so the gist is that the precedence for |
@inamiy Do you want to rebase/squash this down on top of current master and then I'll work at merging it? |
Fix SwiftLint errors
8541c81
to
7a6da19
Compare
@gfontenot Sure! Rebased in 7a6da19. (CI failure seems unrelated) |
@inamiy yeah, the CI failure is because of Xcode 8, which doesn't exist on Circle. Totally expected on my part. |
💥 merged, thanks! |
This pull request adds new Applicative
*>
,<*
, and Alternative<|>
operators, which are needed feature in tryswift/TryParsec#11 and all other functional libraries ✨ (See also: #65)By the way, Argo is currently using the same
<|>
operator in Alternative.swift#L13 withprecedence 140
, but this causes continuous monadic operations not working nicely. For example,m1 *> m2 <|> m3 *> m4
doesn't work and must use parenthesis to work around like(m1 *> m2) <|> (m3 *> m4)
, which is very cumbersome. Since Haskell uses lower precedence for<|>
, I have dropped it down toprecedence 120
(or,precedence 125
might be a better choice as discussed in tryswift/TryParsec#11).I also added comments about Haskell's infix operator precedences for comparison with Runes 👀