001/*
002 * Copyright (c) 2012-2018 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License 2.0 which is available at
006 * http://www.eclipse.org/legal/epl-2.0.
007 *
008 * SPDX-License-Identifier: EPL-2.0
009 */
010package gololang;
011
012import java.util.Iterator;
013
014/**
015 * Wraps a {@code Headtail} into an iterator
016 */
017public class HeadTailIterator<T> implements Iterator<T> {
018  private HeadTail<T> data;
019
020  HeadTailIterator(HeadTail<T> headTail) {
021    this.data = headTail;
022  }
023
024  @Override
025  public boolean hasNext() {
026    return !data.isEmpty();
027  }
028
029  @Override
030  public T next() {
031    T h = data.head();
032    data = data.tail();
033    return h;
034  }
035
036  @Override
037  public void remove() {
038    throw new UnsupportedOperationException("HeadTail object are immutable");
039  }
040}