@@ -16,6 +16,7 @@ structures:
1616* [ Semigroup] ( #semigroup )
1717* [ Monoid] ( #monoid )
1818* [ Group] ( #group )
19+ * [ Filterable] ( #filterable )
1920* [ Functor] ( #functor )
2021* [ Contravariant] ( #contravariant )
2122* [ Apply] ( #apply )
@@ -33,7 +34,7 @@ structures:
3334* [ Bifunctor] ( #bifunctor )
3435* [ Profunctor] ( #profunctor )
3536
36- <img src =" figures/dependencies.png " width =" 888 " height =" 257 " />
37+ <img src =" figures/dependencies.png " width =" 888 " height =" 234 " />
3738
3839## General
3940
@@ -328,6 +329,32 @@ A value which has a Group must provide an `invert` method. The
328329
3293301 . `invert` must return a value of the same Group .
330331
332+ ### Filterable
333+
334+ 1 . `v. filter (x => p(x) && q(x))` is equivalent to `v. filter (p). filter (q)` (distributivity)
335+ 2 . `v. filter (x => true)` is equivalent to `v` (identity)
336+ 3 . `v. filter (x => false)` is equivalent to `w. filter (x => false)`
337+ if `v` and `w` are values of the same Filterable (annihilation)
338+
339+ #### `filter` method
340+
341+ ```hs
342+ filter :: Filterable f => f a ~> (a -> Boolean ) -> f a
343+ ```
344+
345+ A value which has a Filterable must provide a `filter` method. The `filter`
346+ method takes one argument:
347+
348+ v. filter (p)
349+
350+ 1 . `p` must be a function.
351+
352+ 1 . If `p` is not a function, the behaviour of `filter` is unspecified.
353+ 2 . `p` must return either `true` or `false` . If it returns any other value,
354+ the behaviour of `filter` is unspecified.
355+
356+ 2 . `filter` must return a value of the same Filterable .
357+
331358### Functor
332359
3333601 . `u. map (a => a)` is equivalent to `u` (identity)
@@ -836,7 +863,7 @@ to implement certain methods then derive the remaining methods. Derivations:
836863 function(f) {
837864 function Id (value) {
838865 this. value = value;
839- };
866+ }
840867 Id. of = function(x) {
841868 return new Id (x);
842869 };
@@ -850,6 +877,25 @@ to implement certain methods then derive the remaining methods. Derivations:
850877 }
851878 ```
852879
880+ - [`filter` ][] may be derived from [`of` ][] , [`chain` ][] , and [`zero` ][] :
881+
882+ ```js
883+ function(pred ) {
884+ var F = this. constructor;
885+ return this. chain(x => pred (x) ? F. of(x) : F. zero() );
886+ }
887+ ```
888+
889+ - [`filter` ][] may be derived from [`concat` ][] , [`of` ][] , [`zero` ][] , and
890+ [`reduce` ][] :
891+
892+ ```js
893+ function(pred ) {
894+ var F = this. constructor;
895+ return this. reduce((f, x) => pred (x) ? f. concat (F. of(x)) : f, F. zero() );
896+ }
897+ ```
898+
853899If a data type provides a method which * could* be derived, its behaviour must
854900be equivalent to that of the derivation (or derivations).
855901
@@ -873,12 +919,14 @@ be equivalent to that of the derivation (or derivations).
873919[`equals` ]: # equals- method
874920[`extend` ]: # extend- method
875921[`extract` ]: # extract- method
922+ [`filter` ]: # filter - method
876923[`lte` ]: # lte- method
877924[`map` ]: # map - method
878925[`of` ]: # of - method
879926[`promap` ]: # promap- method
880927[`reduce` ]: # reduce- method
881928[`sequence` ]: # sequence - method
929+ [`zero` ]: # zero- method
882930
883931## Alternatives
884932
0 commit comments