{-# LINE 7 "small/ListOps.as" #-}
module Main where
{-# LINE 7 "small/ListOps.as" #-}
import Arrow
 
{-# LINE 9 "small/ListOps.as" #-}
mapA :: (ArrowChoice a) => a (b, c) d -> a (b, [c]) [d]
{-# LINE 10 "small/ListOps.as" #-}
mapA f
  = (arr
       (\ (env, xs) ->
	  case xs of
	      [] -> Left ()
	      x : xs -> Right (env, x, xs))
       >>>
       (arr (\ () -> []) |||
	  (arr (\ (env, x, xs) -> ((env, x), (env, xs))) >>>
	     (first f >>> arr (\ (y, (env, xs)) -> ((env, xs), y))) >>>
	       (first (mapA f) >>> arr (\ (ys, y) -> y : ys)))))
 
{-# LINE 18 "small/ListOps.as" #-}
filterA :: (ArrowChoice a) => a (b, c) Bool -> a (b, [c]) [c]
{-# LINE 19 "small/ListOps.as" #-}
filterA p
  = (arr
       (\ (env, xs) ->
	  case xs of
	      [] -> Left ()
	      x : xs -> Right (env, x, xs))
       >>>
       (arr (\ () -> []) |||
	  (arr (\ (env, x, xs) -> ((env, x), (env, x, xs))) >>>
	     (first p >>> arr (\ (b, (env, x, xs)) -> ((env, xs), (b, x)))) >>>
	       (first (filterA p) >>>
		  arr (\ (ys, (b, x)) -> if b then x : ys else ys)))))
