11## Module FRP.Event
22
3+ #### ` fix `
4+
5+ ``` purescript
6+ fix :: forall i o. (Event i -> { input :: Event i, output :: Event o }) -> Event o
7+ ```
8+
9+ Compute a fixed point
10+
311#### ` fold `
412
513``` purescript
@@ -38,6 +46,7 @@ Events are consumed by providing a callback using the `subscribe` function.
3846##### Instances
3947``` purescript
4048Functor Event
49+ Filterable Event
4150Apply Event
4251Applicative Event
4352Alt Event
@@ -54,49 +63,84 @@ IsEvent Event
5463never :: forall a. Event a
5564```
5665
57- #### ` filter `
66+ #### ` keepLatest `
5867
5968``` purescript
60- filter :: forall a. (a -> Boolean) -> Event a -> Event a
69+ keepLatest :: forall a. Event ( Event a) -> Event a
6170```
6271
63- Create an ` Event ` which only fires when a predicate holds.
72+ Flatten a nested ` Event ` , reporting values only from the most recent
73+ inner ` Event ` .
6474
6575#### ` subscribe `
6676
6777``` purescript
68- subscribe :: forall eff a r. Event a -> (a -> Eff (frp :: FRP | eff) r) -> Eff (frp :: FRP | eff) Unit
78+ subscribe :: forall eff a r. Event a -> (a -> Eff (frp :: FRP | eff) r) -> Eff (frp :: FRP | eff) (Eff (frp :: FRP | eff) Unit)
6979```
7080
7181Subscribe to an ` Event ` by providing a callback.
7282
73- #### ` create `
83+ ` subscribe ` returns a canceller function.
84+
85+
86+ ### Re-exported from Data.Filterable:
87+
88+ #### ` Filterable `
7489
7590``` purescript
76- create :: forall eff a. Eff (frp :: FRP | eff) { event :: Event a, push :: a -> Eff (frp :: FRP | eff) Unit }
91+ class (Functor f) <= Filterable f where
92+ filterMap :: forall a b. (a -> Maybe b) -> f a -> f b
7793```
7894
79- Create an event and a function which supplies a value to that event .
95+ ` Filterable ` represents data structures which can be _ partitioned _ / _ filtered _ .
8096
97+ - ` partitionMap ` - partition a data structure based on an either predicate.
98+ - ` partition ` - partition a data structure based on boolean predicate.
99+ - ` filterMap ` - map over a data structure and filter based on a maybe.
100+ - ` filter ` - filter a data structure based on a boolean.
101+
102+ Laws:
103+ - ` map f ≡ filterMap (Just <<< f) `
104+ - ` filter ≡ filterMap <<< maybeBool `
105+ - ` filterMap p ≡ filter (isJust <<< p) `
106+
107+ Default implementations are provided by the following functions:
108+
109+ - ` partitionDefault `
110+ - ` partitionDefaultFilter `
111+ - ` partitionDefaultFilterMap `
112+ - ` filterDefault `
113+ - ` filterDefaultPartition `
114+ - ` filterDefaultPartitionMap `
115+
116+ ##### Instances
117+ ``` purescript
118+ Filterable Array
119+ Filterable Maybe
120+ (Monoid m) => Filterable (Either m)
121+ Filterable List
122+ (Ord k) => Filterable (Map k)
123+ ```
81124
82125### Re-exported from FRP.Event.Class:
83126
84127#### ` IsEvent `
85128
86129``` purescript
87- class (Alternative event) <= IsEvent event where
130+ class (Alternative event, Filterable event ) <= IsEvent event where
88131 fold :: forall a b. (a -> b -> b) -> event a -> b -> event b
89- mapMaybe :: forall a b. (a -> Maybe b) -> event a -> event b
90132 sampleOn :: forall a b. event a -> event (a -> b) -> event b
133+ fix :: forall i o. (event i -> { input :: event i, output :: event o }) -> event o
91134```
92135
93136Functions which an ` Event ` type should implement, so that
94137` Behavior ` s can be defined in terms of any such event type:
95138
96139- ` fold ` : combines incoming values using the specified function,
97140starting with the specific initial value.
98- - ` mapMaybe ` : discards incoming values which do not satisfy a predicate.
99141- ` sampleOn ` : samples an event at the times when a second event fires.
142+ - ` fix ` : compute a fixed point, by feeding output events back in as
143+ inputs.
100144
101145#### ` withLast `
102146
0 commit comments