Move current result handling out of Base

Delete majority of Base functionality.
This commit is contained in:
kortschak 2014-07-30 15:01:09 +09:30
parent ee6d4c8db7
commit 375d953d93
14 changed files with 140 additions and 82 deletions

View file

@ -43,6 +43,7 @@ type Optional struct {
tags graph.Tagger
subIt graph.Iterator
lastCheck bool
result graph.Value
}
// Creates a new optional iterator.
@ -78,6 +79,9 @@ func (it *Optional) Clone() graph.Iterator {
return out
}
// FIXME(kortschak) When we create a Nexter interface the
// following two methods need to go away.
// Nexting the iterator is unsupported -- error and return an empty set.
// (As above, a reasonable alternative would be to Next() an all iterator)
func (it *Optional) Next() (graph.Value, bool) {
@ -85,6 +89,15 @@ func (it *Optional) Next() (graph.Value, bool) {
return nil, false
}
// DEPRECATED
func (it *Optional) ResultTree() *graph.ResultTree {
return graph.NewResultTree(it.Result())
}
func (it *Optional) Result() graph.Value {
return it.result
}
// An optional iterator only has a next result if, (a) last time we checked
// we had any results whatsoever, and (b) there was another subresult in our
// optional subbranch.
@ -106,7 +119,7 @@ func (it *Optional) SubIterators() []graph.Iterator {
func (it *Optional) Check(val graph.Value) bool {
checked := it.subIt.Check(val)
it.lastCheck = checked
it.Last = val
it.result = val
return true
}