;; -*-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 nonpure-iterator)


  (import (standard-library core))


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

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

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

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

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

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

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

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

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

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

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

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

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

  (declare nonpure-iter-for-each1
	   (:param-proc (%source)
			((:procedure (%source) <none> nonpure)
			 (:nonpure-iterator %source))
			<none>
			nonpure))

  (declare nonpure-iter-for-each2
	   (:param-proc (%source1 %source2)
			((:procedure (%source1 %source2)
				     <none> nonpure)
			 (:nonpure-iterator %source1)
			 (:nonpure-iterator %source2))
			<none>
			nonpure))

  (declare gen-generator
	   (:param-proc (%source %target)
			((:procedure () %source nonpure)
			 (:procedure (%source) <boolean> pure)
			 (:nonpure-consumer %source %target)
			 (:nonpure-iterator-inst %source %target))
			%target
			nonpure))

  (declare generator->iterator
	   (:param-proc (%source)
			((:procedure () %source nonpure)
			 (:procedure (%source) <boolean> pure))
			(:nonpure-iterator %source)
			nonpure)))
