packages feed

idris-0.9.18: libs/effects/Effect/Select.idr

module Effect.Select

import Effects

data Selection : Effect where
     Select : List a -> sig Selection a ()

instance Handler Selection Maybe where
     handle _ (Select xs) k = tryAll xs where
         tryAll [] = Nothing
         tryAll (x :: xs) = case k x () of
                                 Nothing => tryAll xs
                                 Just v => Just v

instance Handler Selection List where
     handle r (Select xs) k = concatMap (\x => k x r) xs

SELECT : EFFECT
SELECT = MkEff () Selection

select : List a -> Eff a [SELECT]
select xs = call $ Select xs