tonymorris/fp-course

L04.ListZipper.findLeft, findRight

bens opened this issue · 5 comments

bens commented

This is more a suggestion.

I noticed that those two functions have a nice algebraic property, what I think is called a zero unit.

(u0 . findLeft f) z == u0 z where u0 = findLeft (const False)

and the same if u0 and findLeft f are swapped.

It'd be nice if they had an identity unit as well, like

(u1 . findLeft f) z == findLeft f z where u1 = findLeft (const True)

but they move at least one spot if they return a result. Would it make sense to change the spec and answers to have that property? If my terminology is off I'd like to be corrected. Cheers,

Ben

To be clear, I think you are saying that if findLeft/findRight stay on the focus if the predicate matches (or if there is no left/right from the focus), then some nicer properties are preserved.

bens commented

Yes, that's right.

I am convinced. I agree.

bens commented

Very good, I'll make some patches this evening if I'm not beaten to it :)

Coolo, I am doing a scala port at the moment.