Skip to content

Commit 31903cd

Browse files
committed
Merge master
2 parents 923306e + bbcbc1a commit 31903cd

21 files changed

+1124
-163
lines changed

.eslintrc.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5
4+
},
5+
"extends": "eslint:recommended",
6+
"env": {
7+
"commonjs": true
8+
},
9+
"rules": {
10+
"strict": [2, "global"],
11+
"block-scoped-var": 2,
12+
"consistent-return": 2,
13+
"eqeqeq": [2, "smart"],
14+
"guard-for-in": 2,
15+
"no-caller": 2,
16+
"no-extend-native": 2,
17+
"no-loop-func": 2,
18+
"no-new": 2,
19+
"no-param-reassign": 2,
20+
"no-return-assign": 2,
21+
"no-unused-expressions": 2,
22+
"no-use-before-define": 2,
23+
"radix": [2, "always"],
24+
"indent": [2, 2],
25+
"quotes": [2, "double"],
26+
"semi": [2, "always"]
27+
}
28+
}

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/.*
22
!/.gitignore
3-
!/.jscsrc
4-
!/.jshintrc
3+
!/.eslintrc.json
54
!/.travis.yml
65
/bower_components/
76
/node_modules/

.jscsrc

Lines changed: 0 additions & 17 deletions
This file was deleted.

.jshintrc

Lines changed: 0 additions & 20 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
dist: trusty
33
sudo: required
4-
node_js: 6
4+
node_js: stable
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# purescript-foldable-traversable
22

3-
[![Latest release](http://img.shields.io/bower/v/purescript-foldable-traversable.svg)](https://github.com/purescript/purescript-foldable-traversable/releases)
4-
[![Build Status](https://travis-ci.org/purescript/purescript-foldable-traversable.svg?branch=master)](https://travis-ci.org/purescript/purescript-foldable-traversable)
5-
[![Dependency Status](https://www.versioneye.com/user/projects/55848b2536386100150003cf/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55848b2536386100150003cf)
3+
[![Latest release](http://img.shields.io/github/release/purescript/purescript-foldable-traversable.svg)](https://github.com/purescript/purescript-foldable-traversable/releases)
4+
[![Build status](https://travis-ci.org/purescript/purescript-foldable-traversable.svg?branch=master)](https://travis-ci.org/purescript/purescript-foldable-traversable)
65

76
Classes for foldable and traversable data structures.
87

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-bifunctors": "^2.0.0",
21-
"purescript-maybe": "^2.0.0"
20+
"purescript-bifunctors": "^3.0.0",
21+
"purescript-maybe": "^3.0.0"
2222
},
2323
"devDependencies": {
2424
"purescript-assert": "^2.0.0",

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "jshint src && jscs src && psa \"src/**/*.purs\" \"bower_components/purescript-*/**/*.purs\" --censor-lib --strict",
6-
"test": "psc \"src/**/*.purs\" \"bower_components/purescript-*/**/*.purs\" \"test/**/*.purs\" && psc-bundle \"output/**/*.js\" --module Test.Main --main Test.Main | node"
5+
"build": "eslint src && pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"jscs": "^2.8.0",
10-
"jshint": "^2.9.1",
11-
"pulp": "^8.2.0",
12-
"purescript-psa": "^0.3.8",
13-
"rimraf": "^2.5.0"
9+
"eslint": "^3.17.1",
10+
"pulp": "^10.0.4",
11+
"purescript-psa": "^0.5.0-rc.1",
12+
"rimraf": "^2.6.1"
1413
}
1514
}

src/Data/Bifoldable.purs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import Data.Monoid.Disj (Disj(..))
1010
import Data.Monoid.Dual (Dual(..))
1111
import Data.Monoid.Endo (Endo(..))
1212
import Data.Newtype (unwrap)
13+
import Data.Foldable (class Foldable, foldr, foldl, foldMap)
14+
import Data.Bifunctor.Clown (Clown(..))
15+
import Data.Bifunctor.Joker (Joker(..))
16+
import Data.Bifunctor.Flip (Flip(..))
17+
import Data.Bifunctor.Product (Product(..))
18+
import Data.Bifunctor.Wrap (Wrap(..))
1319

1420
-- | `Bifoldable` represents data structures with two type arguments which can be
1521
-- | folded.
@@ -33,6 +39,31 @@ class Bifoldable p where
3339
bifoldl :: forall a b c. (c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c
3440
bifoldMap :: forall m a b. Monoid m => (a -> m) -> (b -> m) -> p a b -> m
3541

42+
instance bifoldableClown :: Foldable f => Bifoldable (Clown f) where
43+
bifoldr l _ u (Clown f) = foldr l u f
44+
bifoldl l _ u (Clown f) = foldl l u f
45+
bifoldMap l _ (Clown f) = foldMap l f
46+
47+
instance bifoldableJoker :: Foldable f => Bifoldable (Joker f) where
48+
bifoldr _ r u (Joker f) = foldr r u f
49+
bifoldl _ r u (Joker f) = foldl r u f
50+
bifoldMap _ r (Joker f) = foldMap r f
51+
52+
instance bifoldableFlip :: Bifoldable p => Bifoldable (Flip p) where
53+
bifoldr r l u (Flip p) = bifoldr l r u p
54+
bifoldl r l u (Flip p) = bifoldl l r u p
55+
bifoldMap r l (Flip p) = bifoldMap l r p
56+
57+
instance bifoldableProduct :: (Bifoldable f, Bifoldable g) => Bifoldable (Product f g) where
58+
bifoldr l r u m = bifoldrDefault l r u m
59+
bifoldl l r u m = bifoldlDefault l r u m
60+
bifoldMap l r (Product f g) = bifoldMap l r f <> bifoldMap l r g
61+
62+
instance bifoldableWrap :: Bifoldable p => Bifoldable (Wrap p) where
63+
bifoldr l r u (Wrap p) = bifoldr l r u p
64+
bifoldl l r u (Wrap p) = bifoldl l r u p
65+
bifoldMap l r (Wrap p) = bifoldMap l r p
66+
3667
-- | A default implementation of `bifoldr` using `bifoldMap`.
3768
-- |
3869
-- | Note: when defining a `Bifoldable` instance, this function is unsafe to
@@ -71,36 +102,39 @@ bifoldlDefault f g z p =
71102
-- | use in combination with `bifoldrDefault`.
72103
bifoldMapDefaultR
73104
:: forall p m a b
74-
. (Bifoldable p, Monoid m)
105+
. Bifoldable p
106+
=> Monoid m
75107
=> (a -> m)
76108
-> (b -> m)
77109
-> p a b
78110
-> m
79-
bifoldMapDefaultR f g p = bifoldr (append <<< f) (append <<< g) mempty p
111+
bifoldMapDefaultR f g = bifoldr (append <<< f) (append <<< g) mempty
80112

81113
-- | A default implementation of `bifoldMap` using `bifoldl`.
82114
-- |
83115
-- | Note: when defining a `Bifoldable` instance, this function is unsafe to
84116
-- | use in combination with `bifoldlDefault`.
85117
bifoldMapDefaultL
86118
:: forall p m a b
87-
. (Bifoldable p, Monoid m)
119+
. Bifoldable p
120+
=> Monoid m
88121
=> (a -> m)
89122
-> (b -> m)
90123
-> p a b
91124
-> m
92-
bifoldMapDefaultL f g p = bifoldl (\m a -> m <> f a) (\m b -> m <> g b) mempty p
125+
bifoldMapDefaultL f g = bifoldl (\m a -> m <> f a) (\m b -> m <> g b) mempty
93126

94127

95128
-- | Fold a data structure, accumulating values in a monoidal type.
96-
bifold :: forall t m. (Bifoldable t, Monoid m) => t m m -> m
129+
bifold :: forall t m. Bifoldable t => Monoid m => t m m -> m
97130
bifold = bifoldMap id id
98131

99132
-- | Traverse a data structure, accumulating effects using an `Applicative` functor,
100133
-- | ignoring the final result.
101134
bitraverse_
102135
:: forall t f a b c d
103-
. (Bifoldable t, Applicative f)
136+
. Bifoldable t
137+
=> Applicative f
104138
=> (a -> f c)
105139
-> (b -> f d)
106140
-> t a b
@@ -110,7 +144,8 @@ bitraverse_ f g = bifoldr (applySecond <<< f) (applySecond <<< g) (pure unit)
110144
-- | A version of `bitraverse_` with the data structure as the first argument.
111145
bifor_
112146
:: forall t f a b c d
113-
. (Bifoldable t, Applicative f)
147+
. Bifoldable t
148+
=> Applicative f
114149
=> t a b
115150
-> (a -> f c)
116151
-> (b -> f d)
@@ -121,15 +156,17 @@ bifor_ t f g = bitraverse_ f g t
121156
-- | ignoring the final result.
122157
bisequence_
123158
:: forall t f a b
124-
. (Bifoldable t, Applicative f)
159+
. Bifoldable t
160+
=> Applicative f
125161
=> t (f a) (f b)
126162
-> f Unit
127163
bisequence_ = bitraverse_ id id
128164

129165
-- | Test whether a predicate holds at any position in a data structure.
130166
biany
131167
:: forall t a b c
132-
. (Bifoldable t, BooleanAlgebra c)
168+
. Bifoldable t
169+
=> BooleanAlgebra c
133170
=> (a -> c)
134171
-> (b -> c)
135172
-> t a b
@@ -139,7 +176,8 @@ biany p q = unwrap <<< bifoldMap (Disj <<< p) (Disj <<< q)
139176
-- | Test whether a predicate holds at all positions in a data structure.
140177
biall
141178
:: forall t a b c
142-
. (Bifoldable t, BooleanAlgebra c)
179+
. Bifoldable t
180+
=> BooleanAlgebra c
143181
=> (a -> c)
144182
-> (b -> c)
145183
-> t a b

src/Data/Bitraversable.purs

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ module Data.Bitraversable
22
( class Bitraversable, bitraverse, bisequence
33
, bitraverseDefault
44
, bisequenceDefault
5+
, ltraverse
6+
, rtraverse
57
, bifor
8+
, lfor
9+
, rfor
610
, module Data.Bifoldable
711
) where
812

913
import Prelude
1014

1115
import Data.Bifoldable (class Bifoldable, biall, biany, bifold, bifoldMap, bifoldMapDefaultL, bifoldMapDefaultR, bifoldl, bifoldlDefault, bifoldr, bifoldrDefault, bifor_, bisequence_, bitraverse_)
16+
import Data.Traversable (class Traversable, traverse, sequence)
1217
import Data.Bifunctor (class Bifunctor, bimap)
18+
import Data.Bifunctor.Clown (Clown(..))
19+
import Data.Bifunctor.Joker (Joker(..))
20+
import Data.Bifunctor.Flip (Flip(..))
21+
import Data.Bifunctor.Product (Product(..))
22+
import Data.Bifunctor.Wrap (Wrap(..))
1323

1424
-- | `Bitraversable` represents data structures with two type arguments which can be
1525
-- | traversed.
@@ -26,10 +36,49 @@ class (Bifunctor t, Bifoldable t) <= Bitraversable t where
2636
bitraverse :: forall f a b c d. Applicative f => (a -> f c) -> (b -> f d) -> t a b -> f (t c d)
2737
bisequence :: forall f a b. Applicative f => t (f a) (f b) -> f (t a b)
2838

39+
instance bitraversableClown :: Traversable f => Bitraversable (Clown f) where
40+
bitraverse l _ (Clown f) = Clown <$> traverse l f
41+
bisequence (Clown f) = Clown <$> sequence f
42+
43+
instance bitraversableJoker :: Traversable f => Bitraversable (Joker f) where
44+
bitraverse _ r (Joker f) = Joker <$> traverse r f
45+
bisequence (Joker f) = Joker <$> sequence f
46+
47+
instance bitraversableFlip :: Bitraversable p => Bitraversable (Flip p) where
48+
bitraverse r l (Flip p) = Flip <$> bitraverse l r p
49+
bisequence (Flip p) = Flip <$> bisequence p
50+
51+
instance bitraversableProduct :: (Bitraversable f, Bitraversable g) => Bitraversable (Product f g) where
52+
bitraverse l r (Product f g) = Product <$> bitraverse l r f <*> bitraverse l r g
53+
bisequence (Product f g) = Product <$> bisequence f <*> bisequence g
54+
55+
instance bitraversableWrap :: Bitraversable p => Bitraversable (Wrap p) where
56+
bitraverse l r (Wrap p) = Wrap <$> bitraverse l r p
57+
bisequence (Wrap p) = Wrap <$> bisequence p
58+
59+
ltraverse
60+
:: forall t b c a f
61+
. Bitraversable t
62+
=> Applicative f
63+
=> (a -> f c)
64+
-> t a b
65+
-> f (t c b)
66+
ltraverse f = bitraverse f pure
67+
68+
rtraverse
69+
:: forall t b c a f
70+
. Bitraversable t
71+
=> Applicative f
72+
=> (b -> f c)
73+
-> t a b
74+
-> f (t a c)
75+
rtraverse = bitraverse pure
76+
2977
-- | A default implementation of `bitraverse` using `bisequence` and `bimap`.
3078
bitraverseDefault
3179
:: forall t f a b c d
32-
. (Bitraversable t, Applicative f)
80+
. Bitraversable t
81+
=> Applicative f
3382
=> (a -> f c)
3483
-> (b -> f d)
3584
-> t a b
@@ -39,17 +88,37 @@ bitraverseDefault f g t = bisequence (bimap f g t)
3988
-- | A default implementation of `bisequence` using `bitraverse`.
4089
bisequenceDefault
4190
:: forall t f a b
42-
. (Bitraversable t, Applicative f)
91+
. Bitraversable t
92+
=> Applicative f
4393
=> t (f a) (f b)
4494
-> f (t a b)
45-
bisequenceDefault t = bitraverse id id t
95+
bisequenceDefault = bitraverse id id
4696

4797
-- | Traverse a data structure, accumulating effects and results using an `Applicative` functor.
4898
bifor
4999
:: forall t f a b c d
50-
. (Bitraversable t, Applicative f)
100+
. Bitraversable t
101+
=> Applicative f
51102
=> t a b
52103
-> (a -> f c)
53104
-> (b -> f d)
54105
-> f (t c d)
55106
bifor t f g = bitraverse f g t
107+
108+
lfor
109+
:: forall t b c a f
110+
. Bitraversable t
111+
=> Applicative f
112+
=> t a b
113+
-> (a -> f c)
114+
-> f (t c b)
115+
lfor t f = bitraverse f pure t
116+
117+
rfor
118+
:: forall t b c a f
119+
. Bitraversable t
120+
=> Applicative f
121+
=> t a b
122+
-> (b -> f c)
123+
-> f (t a c)
124+
rfor t f = bitraverse pure f t

0 commit comments

Comments
 (0)