- An overload that allows datums to report their size through length(). The most important of the three in my mind.
- An overload for "if (x in y)". A would-be-nice.
- An overload for "for (x in y)" that allows datums to be interrogated for the next item to supply to the loop, and then cleanup behavior at the end. Probably the least feasible of the three but nice for writing cleaner code.
For example, I might have
/tree
var/node/__head
var/list/node/__to_visit
/tree/New()
__head = new
/tree/operator+=(entry) // just for illustration
var/node/node = __head
while (TRUE)
if (!node.data)
node.data = entry
break
if (entry > node.data)
if (!node.right)
node.right = new /node
node = node.right
else if (entry < node.data)
if (!node.left)
node.left = new /node
node = node.left
// this might need some magic parameter that can be returned
// to signal an end of items rather than just a null
/tree/proc/operator_for()
if (!__to_visit)
__to_visit = list(__head)
var/last = length(__to_visit)
if (!last)
return
var/node/node = __to_visit[last]
--__to_visit.len
if (node.right)
__to_visit += node.right
if (node.left)
__to_visit += node.left
return node
/tree/proc/operator_for_done()
__to_visit = null
// horrendous, but for the point-
/tree/proc/operator_length()
var/count = 0
for (var/node in src)
++count
return count
/tree/proc/operator_in(entry)
for (var/node/node in src)
if (node.data == entry)
return TRUE
return FALSE
(not sure other single overloading is allowed since doc only says - and ~)
but honestly I'd want to have length or in overloading as a datum mimicing a list is handy