package OOscheme.visitor; import OOscheme.*; /** * Extracts the even-indexed elements of a list. * @author DXN */ public class EvenIndexed implements IListAlgo { public static final EvenIndexed Singleton = new EvenIndexed(); private EvenIndexed() { } /** * The list consisting of the even-indexed elements of an empty list is * an empty list. * @param host an empty list. * @param nu not used * @return IEmptyList, the host itself. */ public Object emptyCase(IEmptyList host, Object... nu) { return host; } /** * The even-indexed elements of a non-empty list consist of its first * followed by the odd-indexed elements of its rest. * @param host a non-empty list * @param nu not used * @return IList */ public Object nonEmptyCase(INEList host, Object... nu) { return new NEList(host.getFirst(), (IList)host.getRest().execute(OddIndexed.Singleton)); } }
package OOscheme.visitor; import OOscheme.*; /** * Extracts the odd-indexed elements of a list. * @author DXN */ public class OddIndexed implements IListAlgo { public static final OddIndexed Singleton = new OddIndexed(); private OddIndexed() { } /** * The list consisting of the odd-indexed elements of an empty list is * an empty list. * @param host an empty list. * @param nu not used * @return IEmptyList, the host itself. */ public Object emptyCase(IEmptyList host, Object... nu) { return host; } /** * The odd-indexed elements of a non-empty list are the even-indexed * elements of its rest. * @param host a non-empty list * @param nu not used * @return IList */ public Object nonEmptyCase(INEList host, Object... nu) { return host.getRest().execute(EvenIndexed.Singleton); } }