note
	description: "Objects that are able to iterate over linear structures"
	library: "Free implementation of ELKS library"
	legal: "See notice at end of class."
	status: "See notice at end of class."
	names: iterators, iteration, linear_iterators, linear_iteration
	date: "$Date: 2015-12-17 13:34:17 +0000 (Thu, 17 Dec 2015) $"
	revision: "$Revision: 98279 $"

class interface
	LINEAR_ITERATOR [G]

create 
	set

feature -- Initialization

	set (s: like target)
			-- Make s the new target of iterations.
	
feature -- Access

	item: G
			-- The item at cursor position in target
		require
			not_off: not target.off

	item_tuple: TUPLE [G]
			-- Tuple containing a single element,
			-- the item at cursor position in target''
		require
			not_off: not target.off
		ensure
			item_tuple_attached: Result /= Void

	target: LINEAR [G]
			-- The structure to which iteration features will apply.
	
feature -- Cursor movement

	start
			-- Move to first position of target.

	forth
			-- Move to next position of target.

	off: BOOLEAN
			-- Is position of target off?

	exhausted: BOOLEAN
			-- Is target exhausted?
	
feature -- Iteration

	do_while (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- and including first one not satisfying test.
			-- (from the start of target)
		ensure then
			finished: not exhausted implies not test.item ([target.item])

	continue_while (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- and including first one not satisfying test
			-- (from the current position of target).
		require else
			invariant_satisfied: invariant_value
		ensure then
			finished: not exhausted implies not test.item ([target.item])

	while_do (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- but excluding first one not satisfying test.
			-- (Apply to full list if all items satisfy test.)
		ensure then
			finished: not exhausted implies not test.item ([target.item])

	while_continue (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- but excluding first one not satisfying test.
		ensure
			finished: not exhausted implies not test.item ([target.item])

	until_do (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- but excluding first one satisfying test.
			-- (Apply to full list if no item satisfies test.)
		ensure then
			achieved: not exhausted implies test.item ([target.item])

	until_continue (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target from current
			-- position, up to but excluding first one satisfying test.
		require
			invariant_satisfied: invariant_value
		ensure
			achieved: exhausted or else test.item ([target.item])
			invariant_satisfied: invariant_value

	do_until (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- and including first one satisfying test.
		ensure then
			achieved: not exhausted implies test.item ([target.item])

	continue_until (action: PROCEDURE [G]; test: FUNCTION [G, BOOLEAN])
			-- Apply action to every item of target up to
			-- and including first one satisfying test.
			-- (from the current position of target).
		require
			invariant_satisfied: invariant_value
		ensure then
			achieved: not exhausted implies test.item ([target.item])

	search (test: FUNCTION [G, BOOLEAN]; b: BOOLEAN)
			-- Search the first item of target for which test
			-- has the same value as b (both true or both false).

	continue_search (test: FUNCTION [G, BOOLEAN]; b: BOOLEAN)
			-- Search the first item of target
			-- satisfying: test equals to b
			-- (from the current position of target).
		ensure then
			found: not exhausted = (b = test.item ([target.item]))

	do_for (action: PROCEDURE [G]; i, n, k: INTEGER_32)
			-- Apply action to every k-th item,
			-- n times if possible, starting from i-th.
		require
			valid_start: i >= 1
			valid_repetition: n >= 0
			valid_skip: k >= 1

	continue_for (action: PROCEDURE [G]; n, k: INTEGER_32)
			-- Apply action to every k-th item,
			-- n times if possible.
		require
			valid_repetition: n >= 0
			valid_skip: k >= 1

	for_all (test: FUNCTION [G, BOOLEAN]): BOOLEAN
			-- Does test return true for
			-- all items of target?

	there_exists (test: FUNCTION [G, BOOLEAN]): BOOLEAN
			-- Does test return true for
			-- at least one item of target?
	
invariant
	target_exists: target /= Void

note
	copyright: "Copyright (c) 1984-2012, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class LINEAR_ITERATOR

Generated by ISE EiffelStudio