;; -*-theme-d-*-

;; Copyright (C) 2016 Tommi Höynälänmaa
;; Distributed under GNU Lesser General Public License version 3,
;; see file doc/LGPL-3.

(define-interface (standard-library iterator)


  (import (standard-library core))


  (declare :consumer <param-logical-type>)

  (define-param-logical-type :iterator-inst (%source %target)
    (:procedure ((:consumer %source %target)) %target pure))

  (define-param-logical-type :iterator (%source)
    (:param-proc (%target) ((:consumer %source %target)) %target pure))

  (define-param-logical-type :consumer (%source %target)
    (:procedure ((:maybe %source) <boolean>
		 (:maybe (:iterator-inst %source %target)))
		%target pure))

  (declare end-iter (:param-proc (%source %target)
				 ((:consumer %source %target))
				 %target pure))

  (declare gen-list (:param-proc (%source %target)
				 ((:uniform-list %source)
				  (:consumer %source %target)
				  (:iterator-inst %source %target))
				  %target pure))

  (declare get-list-iterator (:param-proc (%source)
					  ((:uniform-list %source))
					  (:iterator %source)
					  pure))

  (declare gen-mutable-vector (:param-proc (%source %target)
					   ((:mutable-vector %source)
					    (:consumer %source %target)
					    (:iterator-inst %source %target))
					   %target pure))

  (declare get-mutable-vector-iterator
	   (:param-proc (%source)
			((:mutable-vector %source))
			(:iterator %source)
			pure))

  (declare iter-map1 (:param-proc (%source %component)
				  ((:procedure (%source) %component pure)
				   (:iterator %source))
				  (:uniform-list %component)
				  pure))

  (declare iter-map2 (:param-proc (%source1 %source2 %component)
				  ((:procedure (%source1 %source2)
					       %component pure)
				   (:iterator %source1)
				   (:iterator %source2))
				  (:uniform-list %component)
				  pure))

  (declare iter-every1 (:param-proc (%source)
				    ((:procedure (%source) <boolean> pure)
				     (:iterator %source))
				    <boolean>
				    pure))

  (declare iter-every2 (:param-proc (%source1 %source2)
				    ((:procedure (%source1 %source2)
						 <boolean> pure)
				     (:iterator %source1)
				     (:iterator %source2))
				    <boolean>
				    pure)))
