|
786 | 786 | //. ```
|
787 | 787 | S.invert = def('invert', {g: [Z.Group]}, [g, g], Z.invert);
|
788 | 788 |
|
| 789 | + //# filter :: Filterable f => (a -> Boolean) -> f a -> f a |
| 790 | + //. |
| 791 | + //. Curried version of [`Z.filter`][]. Discards every element which does not |
| 792 | + //. satisfy the predicate. |
| 793 | + //. |
| 794 | + //. See also [`reject`](#reject). |
| 795 | + //. |
| 796 | + //. ```javascript |
| 797 | + //. > S.filter(S.odd, [1, 2, 3]) |
| 798 | + //. [1, 3] |
| 799 | + //. |
| 800 | + //. > S.filter(S.odd, {x: 1, y: 2, z: 3}) |
| 801 | + //. {x: 1, z: 3} |
| 802 | + //. |
| 803 | + //. > S.filter(S.odd, S.Nothing) |
| 804 | + //. Nothing |
| 805 | + //. |
| 806 | + //. > S.filter(S.odd, S.Just(0)) |
| 807 | + //. Nothing |
| 808 | + //. |
| 809 | + //. > S.filter(S.odd, S.Just(1)) |
| 810 | + //. Just(1) |
| 811 | + //. ``` |
| 812 | + S.filter = |
| 813 | + def('filter', {f: [Z.Filterable]}, [$.Predicate(a), f(a), f(a)], Z.filter); |
| 814 | + |
| 815 | + //# reject :: Filterable f => (a -> Boolean) -> f a -> f a |
| 816 | + //. |
| 817 | + //. Curried version of [`Z.reject`][]. Discards every element which satisfies |
| 818 | + //. the predicate. |
| 819 | + //. |
| 820 | + //. See also [`filter`](#filter). |
| 821 | + //. |
| 822 | + //. ```javascript |
| 823 | + //. > S.reject(S.odd, [1, 2, 3]) |
| 824 | + //. [2] |
| 825 | + //. |
| 826 | + //. > S.reject(S.odd, {x: 1, y: 2, z: 3}) |
| 827 | + //. {y: 2} |
| 828 | + //. |
| 829 | + //. > S.reject(S.odd, S.Nothing) |
| 830 | + //. Nothing |
| 831 | + //. |
| 832 | + //. > S.reject(S.odd, S.Just(0)) |
| 833 | + //. Just(0) |
| 834 | + //. |
| 835 | + //. > S.reject(S.odd, S.Just(1)) |
| 836 | + //. Nothing |
| 837 | + //. ``` |
| 838 | + S.reject = |
| 839 | + def('reject', {f: [Z.Filterable]}, [$.Predicate(a), f(a), f(a)], Z.reject); |
| 840 | + |
| 841 | + //# takeWhile :: Filterable f => (a -> Boolean) -> f a -> f a |
| 842 | + //. |
| 843 | + //. Curried version of [`Z.takeWhile`][]. Discards the first element which |
| 844 | + //. does not satisfy the predicate, and all subsequent elements. |
| 845 | + //. |
| 846 | + //. See also [`dropWhile`](#dropWhile). |
| 847 | + //. |
| 848 | + //. ```javascript |
| 849 | + //. > S.takeWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]) |
| 850 | + //. [3, 3, 3, 7] |
| 851 | + //. |
| 852 | + //. > S.takeWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]) |
| 853 | + //. [] |
| 854 | + //. ``` |
| 855 | + S.takeWhile = |
| 856 | + def('takeWhile', |
| 857 | + {f: [Z.Filterable]}, |
| 858 | + [$.Predicate(a), f(a), f(a)], |
| 859 | + Z.takeWhile); |
| 860 | + |
| 861 | + //# dropWhile :: Filterable f => (a -> Boolean) -> f a -> f a |
| 862 | + //. |
| 863 | + //. Curried version of [`Z.dropWhile`][]. Retains the first element which |
| 864 | + //. does not satisfy the predicate, and all subsequent elements. |
| 865 | + //. |
| 866 | + //. See also [`takeWhile`](#takeWhile). |
| 867 | + //. |
| 868 | + //. ```javascript |
| 869 | + //. > S.dropWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]) |
| 870 | + //. [6, 3, 5, 4] |
| 871 | + //. |
| 872 | + //. > S.dropWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]) |
| 873 | + //. [3, 3, 3, 7, 6, 3, 5, 4] |
| 874 | + //. ``` |
| 875 | + S.dropWhile = |
| 876 | + def('dropWhile', |
| 877 | + {f: [Z.Filterable]}, |
| 878 | + [$.Predicate(a), f(a), f(a)], |
| 879 | + Z.dropWhile); |
| 880 | + |
789 | 881 | //# map :: Functor f => (a -> b) -> f a -> f b
|
790 | 882 | //.
|
791 | 883 | //. Curried version of [`Z.map`][].
|
|
1225 | 1317 | [Fn(b, a), f(a), f(b)],
|
1226 | 1318 | Z.contramap);
|
1227 | 1319 |
|
1228 |
| - //# filter :: (Applicative f, Foldable f, Monoid (f a)) => (a -> Boolean) -> f a -> f a |
1229 |
| - //. |
1230 |
| - //. Curried version of [`Z.filter`][]. Filters its second argument in |
1231 |
| - //. accordance with the given predicate. |
1232 |
| - //. |
1233 |
| - //. See also [`filterM`](#filterM). |
1234 |
| - //. |
1235 |
| - //. ```javascript |
1236 |
| - //. > S.filter(S.odd, [1, 2, 3, 4, 5]) |
1237 |
| - //. [1, 3, 5] |
1238 |
| - //. ``` |
1239 |
| - S.filter = |
1240 |
| - def('filter', |
1241 |
| - {f: [Z.Applicative, Z.Foldable, Z.Monoid]}, |
1242 |
| - [$.Predicate(a), f(a), f(a)], |
1243 |
| - Z.filter); |
1244 |
| - |
1245 |
| - //# filterM :: (Alternative m, Monad m) => (a -> Boolean) -> m a -> m a |
1246 |
| - //. |
1247 |
| - //. Curried version of [`Z.filterM`][]. Filters its second argument in |
1248 |
| - //. accordance with the given predicate. |
1249 |
| - //. |
1250 |
| - //. See also [`filter`](#filter). |
1251 |
| - //. |
1252 |
| - //. ```javascript |
1253 |
| - //. > S.filterM(S.odd, [1, 2, 3, 4, 5]) |
1254 |
| - //. [1, 3, 5] |
1255 |
| - //. |
1256 |
| - //. > S.filterM(S.odd, S.Just(9)) |
1257 |
| - //. Just(9) |
1258 |
| - //. |
1259 |
| - //. > S.filterM(S.odd, S.Just(4)) |
1260 |
| - //. Nothing |
1261 |
| - //. ``` |
1262 |
| - S.filterM = |
1263 |
| - def('filterM', |
1264 |
| - {m: [Z.Alternative, Z.Monad]}, |
1265 |
| - [$.Predicate(a), m(a), m(a)], |
1266 |
| - Z.filterM); |
1267 |
| - |
1268 |
| - //# takeWhile :: (Foldable f, Alternative f) => (a -> Boolean) -> f a -> f a |
1269 |
| - //. |
1270 |
| - //. Discards the first inner value which does not satisfy the predicate, and |
1271 |
| - //. all subsequent inner values. |
1272 |
| - //. |
1273 |
| - //. ```javascript |
1274 |
| - //. > S.takeWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]) |
1275 |
| - //. [3, 3, 3, 7] |
1276 |
| - //. |
1277 |
| - //. > S.takeWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]) |
1278 |
| - //. [] |
1279 |
| - //. ``` |
1280 |
| - S.takeWhile = |
1281 |
| - def('takeWhile', |
1282 |
| - {f: [Z.Foldable, Z.Alternative]}, |
1283 |
| - [$.Predicate(a), f(a), f(a)], |
1284 |
| - Z.takeWhile); |
1285 |
| - |
1286 |
| - //# dropWhile :: (Foldable f, Alternative f) => (a -> Boolean) -> f a -> f a |
1287 |
| - //. |
1288 |
| - //. Retains the first inner value which does not satisfy the predicate, and |
1289 |
| - //. all subsequent inner values. |
1290 |
| - //. |
1291 |
| - //. ```javascript |
1292 |
| - //. > S.dropWhile(S.odd, [3, 3, 3, 7, 6, 3, 5, 4]) |
1293 |
| - //. [6, 3, 5, 4] |
1294 |
| - //. |
1295 |
| - //. > S.dropWhile(S.even, [3, 3, 3, 7, 6, 3, 5, 4]) |
1296 |
| - //. [3, 3, 3, 7, 6, 3, 5, 4] |
1297 |
| - //. ``` |
1298 |
| - S.dropWhile = |
1299 |
| - def('dropWhile', |
1300 |
| - {f: [Z.Foldable, Z.Alternative]}, |
1301 |
| - [$.Predicate(a), f(a), f(a)], |
1302 |
| - Z.dropWhile); |
1303 |
| - |
1304 | 1320 | //. ### Combinator
|
1305 | 1321 |
|
1306 | 1322 | //# I :: a -> a
|
|
1828 | 1844 | other.isNothing ? this : Just(Z.concat(this.value, other.value));
|
1829 | 1845 | }
|
1830 | 1846 |
|
| 1847 | + //# Maybe#fantasy-land/filter :: Maybe a ~> (a -> Boolean) -> Maybe a |
| 1848 | + //. |
| 1849 | + //. Takes a predicate and returns `this` if `this` is a Just and this Just's |
| 1850 | + //. value satisfies the given predicate; Nothing otherwise. |
| 1851 | + //. |
| 1852 | + //. It is idiomatic to use [`filter`](#filter) rather than use this method |
| 1853 | + //. directly. |
| 1854 | + //. |
| 1855 | + //. ```javascript |
| 1856 | + //. > S.filter(S.odd, S.Nothing) |
| 1857 | + //. Nothing |
| 1858 | + //. |
| 1859 | + //. > S.filter(S.odd, S.Just(0)) |
| 1860 | + //. Nothing |
| 1861 | + //. |
| 1862 | + //. > S.filter(S.odd, S.Just(1)) |
| 1863 | + //. Just(1) |
| 1864 | + //. ``` |
| 1865 | + Maybe.prototype['fantasy-land/filter'] = function(pred) { |
| 1866 | + return this.isJust && pred(this.value) ? this : Nothing; |
| 1867 | + }; |
| 1868 | + |
1831 | 1869 | //# Maybe#fantasy-land/map :: Maybe a ~> (a -> b) -> Maybe b
|
1832 | 1870 | //.
|
1833 | 1871 | //. Takes a function and returns `this` if `this` is Nothing; otherwise
|
|
4689 | 4727 | //. [`Z.compose`]: v:sanctuary-js/sanctuary-type-classes#compose
|
4690 | 4728 | //. [`Z.concat`]: v:sanctuary-js/sanctuary-type-classes#concat
|
4691 | 4729 | //. [`Z.contramap`]: v:sanctuary-js/sanctuary-type-classes#contramap
|
| 4730 | +//. [`Z.dropWhile`]: v:sanctuary-js/sanctuary-type-classes#dropWhile |
4692 | 4731 | //. [`Z.duplicate`]: v:sanctuary-js/sanctuary-type-classes#duplicate
|
4693 | 4732 | //. [`Z.empty`]: v:sanctuary-js/sanctuary-type-classes#empty
|
4694 | 4733 | //. [`Z.equals`]: v:sanctuary-js/sanctuary-type-classes#equals
|
4695 | 4734 | //. [`Z.extend`]: v:sanctuary-js/sanctuary-type-classes#extend
|
4696 | 4735 | //. [`Z.extract`]: v:sanctuary-js/sanctuary-type-classes#extract
|
4697 | 4736 | //. [`Z.filter`]: v:sanctuary-js/sanctuary-type-classes#filter
|
4698 |
| -//. [`Z.filterM`]: v:sanctuary-js/sanctuary-type-classes#filterM |
4699 | 4737 | //. [`Z.gt`]: v:sanctuary-js/sanctuary-type-classes#gt
|
4700 | 4738 | //. [`Z.gte`]: v:sanctuary-js/sanctuary-type-classes#gte
|
4701 | 4739 | //. [`Z.id`]: v:sanctuary-js/sanctuary-type-classes#id
|
|
4706 | 4744 | //. [`Z.map`]: v:sanctuary-js/sanctuary-type-classes#map
|
4707 | 4745 | //. [`Z.of`]: v:sanctuary-js/sanctuary-type-classes#of
|
4708 | 4746 | //. [`Z.promap`]: v:sanctuary-js/sanctuary-type-classes#promap
|
| 4747 | +//. [`Z.reject`]: v:sanctuary-js/sanctuary-type-classes#reject |
4709 | 4748 | //. [`Z.sequence`]: v:sanctuary-js/sanctuary-type-classes#sequence
|
| 4749 | +//. [`Z.takeWhile`]: v:sanctuary-js/sanctuary-type-classes#takeWhile |
4710 | 4750 | //. [`Z.toString`]: v:sanctuary-js/sanctuary-type-classes#toString
|
4711 | 4751 | //. [`Z.traverse`]: v:sanctuary-js/sanctuary-type-classes#traverse
|
4712 | 4752 | //. [`Z.zero`]: v:sanctuary-js/sanctuary-type-classes#zero
|
|
0 commit comments