Skip to content

Commit 34ea87a

Browse files
committed
Add loopState'
1 parent 216c9da commit 34ea87a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Concur/Core/Patterns.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Concur.Core.Patterns
22
( loopState
3+
, loopState'
34
, retryUntil
45
, retryUntilLoop
56
, tea
@@ -29,6 +30,7 @@ import Effect.Aff.Bus as ABus
2930
import Effect.Aff.Class (class MonadAff, liftAff)
3031
import Effect.Class (class MonadEffect, liftEffect)
3132

33+
3234
-- | A very useful combinator for widgets with localised state
3335
loopState ::
3436
forall m a s.
@@ -40,6 +42,10 @@ loopState s f = f s >>= case _ of
4042
Left s' -> loopState s' f
4143
Right a -> pure a
4244

45+
-- | Never ending widgets with localised state
46+
loopState' :: forall m a s. Monad m => (s -> m s) -> s -> m a
47+
loopState' f s = f s >>= loopState' f
48+
4349
-- | Repeat a computation until the value satisfies a predicate
4450
retryUntil :: forall m a. Monad m => (a -> Boolean) -> m a -> m a
4551
retryUntil p w = w >>= \a -> if p a then pure a else retryUntil p w

0 commit comments

Comments
 (0)