Try a separate holdKnown primitive

This commit is contained in:
MasseR committed 2026-10-12 11:11:37 +03:00
1 parent 8a4a5aef33
commit 55855db55b
2 files changed
+10 -3

No files matched your search

+6
View File
@@ -8,6 +8,7 @@ module AFRP
, withEntities
, Event(..)
, hold
, holdKnown
, events
-- , switch
, preMapAccum
@@ -326,6 +327,11 @@ hold def = mapAccum step def id
Tick -> prev
Event new -> new
-- A variant of 'hold' which makes it explicit whether we have a previous value
holdKnown :: (Serialize a, Eq a) => Mealy m (Event a) (Maybe a)
holdKnown = arr (fmap Just) >>> hold Nothing
snapshot :: (Serialize a, Eq a) => a -> Mealy m (Event (), a) a
snapshot def = mapAccum step def id
where