-
Notifications
You must be signed in to change notification settings - Fork 7
Conversation
Nice, looks good! I’ll do a more thorough review later on, but for now, could you please document all public functionality? Copying the docs from |
public let predicate: Element -> Bool | ||
|
||
public init() { | ||
self.predicate = { (element: Element) in false } |
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.
Suggest { _ in false }
Because I forgot to note it: review complete ✨ |
Alright, I think this is now ready to go! 🎉 |
self.predicate = { element in | ||
return predicate(element) != nil | ||
} | ||
} |
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.
Since we’ve removed Q
and family, I think we can probably remove this as well. I’m primarily concerned about it being confusing because:
- every type
T
is promotable toOptional<T>
, and - the returned
PredicateSet
bears no relationship toT
whatsoever.
I.e. by my understanding of Swift’s rules, you could write PredicateSet<String>(count)
right now and be very confused as to why it contains ""
.
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.
Also, the penalty for removing this is that consumers have to do an explicit nil
comparison which they ought to be doing anyway for clarity’s sake.
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 few small notes. This is looking really great! For full set comprehensions (with |
@robrix Ooh, interesting! Could you elaborate more on how that would look? |
✨ |
🎉 🎊 |
@amackworth Upon reflection, monoids might not actually suffice. I was thinking of structural induction, a la the typical inductive definition of Fortunately, that would be more complicated than we require: I think we’d just want (potentially infinite) That would give us e.g.:
In Swift’s notation, we might instead say: lazy(0..<Int.max)
.filter { $0 < 5 }
.map { 2 * $0 + 1 } But we want a couple of extra things from this:
I have some ideas about how we can achieve both of those but they’re a bit nebulous and hand-wavy. Specifically, I’m passing init<T>(HalfOpenInterval<T>, (T -> PredicateTerm<T>), T, T -> Element)
…
public enum PredicateTerm<T: Comparable> {
case LessThan(Box<T>)
…
func apply(x: T) -> Bool {
switch self {
case let LessThan(v):
return x < v.value
…
}
}
}
…
public prefix func < <T: Comparable>(x: T) -> PredicateTerm<T> {
return PredicateTerm.LessThan(Box(x))
} and thus retain the information we need about both the input sequence and the predicate to ensure the comprehension is finite. |
There’s a lot of inspiration to be found in LINQ and Parallel LINQ, too. |
A stab at addressing #30.
😸