Posted: 7 Mar 2014 9:43
First of all I think the intension was different. Iterate (from front) until you encounter an element that fulfill a certain requirement, skip that element? and the rest. So if no element fullfils the requirement you will iterate to the end of the list.
before_nd does nothing if the element is not in the list (i.e. something quite different).
Secondly, you predicate is highly inefficient. Running member on a list is O(N) (i.e. proportional to the number of elements in the list). At each of up to N steps you have an operation O(N) operation. Meaning that you algorithm is O(N*N).
The before_nd functionality that you have implemented can easily be acomplished by an O(N) predicate.
Exersize: Create an O(N) implementation of before_nd.
By the way I don't think any of these predicates are adequade for the list class. I think they lack clarity (it is not obvious what they do) and secondly the usability seem a little limited. Furthermore, the number of variations that such predicates could have is endless, and if there are too many variants it becomes very difficult to remember which one does what (and thus to find the one that you need in a certain context).
before_nd does nothing if the element is not in the list (i.e. something quite different).
Secondly, you predicate is highly inefficient. Running member on a list is O(N) (i.e. proportional to the number of elements in the list). At each of up to N steps you have an operation O(N) operation. Meaning that you algorithm is O(N*N).
The before_nd functionality that you have implemented can easily be acomplished by an O(N) predicate.
Exersize: Create an O(N) implementation of before_nd.
By the way I don't think any of these predicates are adequade for the list class. I think they lack clarity (it is not obvious what they do) and secondly the usability seem a little limited. Furthermore, the number of variations that such predicates could have is endless, and if there are too many variants it becomes very difficult to remember which one does what (and thus to find the one that you need in a certain context).