| 944 | } |
| 945 | |
| 946 | const visitFull = <K, V, A>( |
| 947 | node: Node.Node<K, V>, |
| 948 | visit: (key: K, value: V) => Option.Option<A> |
| 949 | ): Option.Option<A> => { |
| 950 | let current: Node.Node<K, V> | undefined = node |
| 951 | let stack: Stack.Stack<Node.Node<K, V>> | undefined = undefined |
| 952 | let done = false |
| 953 | while (!done) { |
| 954 | if (current != null) { |
| 955 | stack = Stack.make(current, stack) |
| 956 | current = current.left |
| 957 | } else if (stack != null) { |
| 958 | const value = visit(stack.value.key, stack.value.value) |
| 959 | if (Option.isSome(value)) { |
| 960 | return value |
| 961 | } |
| 962 | current = stack.value.right |
| 963 | stack = stack.previous |
| 964 | } else { |
| 965 | done = true |
| 966 | } |
| 967 | } |
| 968 | return Option.none() |
| 969 | } |
| 970 | |
| 971 | const visitGreaterThanEqual = <K, V, A>( |
| 972 | node: Node.Node<K, V>, |