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
use struct instead of class, overloading operators #5
Conversation
Note: as far as I can tell, the current version doesn't allow you to use VerEx in a .then method, but it should. I'll think about it and fix it when possible. |
Ping! @jehna |
@@ -6,13 +6,15 @@ | |||
// Copyright (c) 2014 Dominique d'Argent. All rights reserved. | |||
// | |||
|
|||
//: Playground - noun: a place where people can play |
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.
What's this?
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.
Sorry, was using a playground to type and test it out. Will get rid of it in a new commit.
@nmn seems that there are some tests that are failing. Can you check those out? |
Sure thing. Get back to you with updates soon |
The tests should be fixed now. But I'll confirm later today. |
public func startOfLine(enabled enabled: Bool = true) -> VerbalExpressions { | ||
return VerbalExpressions( | ||
prefixes: enabled ? "^" : "", | ||
source: self.source, |
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.
I think self.
is discouraged when not necessarily needed.
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.
Not seen it mentioned either way. self.
just feels a little more explicit to me. I don't have any strong feeling about that however, I'll clean them up.
Thanks for working on that! |
Instead of going with full fledged Lenses, I've defined an overloaded Also, I've gotten rid of |
Good call - I think that's a better approach. |
@nmn Great idea, much simpler! Final nitpicks, then I'm happy to merge:
|
Regarding my second point, I was thinking about something like this: public struct A {
private let x: String
private let y: String
private let z: String
}
private extension A {
func set(x x: String? = nil, y: String? = nil, z: String? = nil) -> A {
return A(
x: x ?? self.x,
y: y ?? self.y,
z: z ?? self.z
)
}
}
let a = A(x: "Hello", y: "world", z: "!")
String(a) // => "A(x: "Hello", y: "world", z: "!")"
let b = a.set(y: "nubbel")
String(b) // => "A(x: "Hello", y: "nubbel", z: "!")"
let c = b.set(x: "Bonjour")
String(c) // => "A(x: "Bonjour", y: "nubbel", z: "!")" What would you say? |
@nubbel that's a better approach - can't believe I didn't spot it myself. |
@nubbel that looks great. Didn't know I could combine optionals and default values like that. I'll make the update. |
return try! NSRegularExpression(pattern: pattern, options: options) | ||
} | ||
|
||
func set(prefixes prefixes: String? = nil, source: String? = nil, suffixes: String? = nil, suffixes: NSRegularExpressionOptions? = nil) -> A { |
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.
A
should probably be VerbalExpressions
;)
Looks good to me now! |
DONE |
use struct instead of class, overloading operators
Thanks! |
if
a =~ b
is true,b =~ a
should also be true. This can be done because string matching is commutative.