Closed eed3si9n closed 13 years ago
Here's from REPL (I temporarily added printMap
):
scala> (books filter (books(1) !=)) printMap
Vector(Some((0,2,<function2>,Map(0 -> Set(0), 1 -> Set(), 2 -> Set(1)))))
scala> (books filter (books(1) !=) filter (books(0) !=)) printMap
Vector(Some((0,1,<function2>,Map(0 -> Set(), 2 -> Set(0)))))
Sorry for any duplicated work; I was trying to fix this as an exercise to help me understand Zipper and came up with a fix before I saw your commits. That said, I don't think your fix is correct. For an example that fails, try:
val foo = <parent><a/><b/><c/></parent>.convert
val elems = foo \ *
val shouldBeEmpty = (foo \ *) filter (elems(0) == ) filter (elems(0) !=)
val result = shouldBeEmpty.unselect
The result should just be
<parent/>
but your Zipper yields
<parent><c/></parent>
The basic problem (I think) is the keys in childMap are supposed to be indexes into the parent rather than indexes into "this" group.
Anyway, the commit in my previous comment works for the above example as well as your original case.
@josharnold52 I was trying as an exercise myself, and it's great that you've put in the work and also found my mistake.
The basic problem (I think) is the keys in childMap are supposed to be indexes into the parent rather than indexes into "this" group.
I kind of had similar thoughts, but it was hazy. Your description of the problem makes sense.
That'll teach me to actually read once in a while…
I didn't see this whole thread, and so I marked this issue as closed when Josh's fix hasn't actually been merged yet. @josharnold52, could you create a pull request for your commit? It's just to make sure there's a paper trail for code usage rights.
Sure, I've crated the pull request.
I am assuming Zippers are supposed to behave like a normal collection. Let me know if this is not the case.
steps
run this from
$ sbt console
:this produces the following outputs:
problem
res1
includes<a/>
I filtered in the earlier filter.expectations
Filtering can be chained multiple times:
note
This is the implementation of
filter
:collect
is equally short, so the problem is likely in theflatMap
. I have an impl for some more context-aware Zipper operations, but it's not working because of this.