Skip to content

Commit

Permalink
Merge pull request #90 from purescript-contrib/compiler/0.12
Browse files Browse the repository at this point in the history
Compiler/0.12
  • Loading branch information
kritzcreek committed May 25, 2018
2 parents 2d10428 + b8627f3 commit 54138b0
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 93 deletions.
14 changes: 10 additions & 4 deletions .travis.yml
@@ -1,15 +1,21 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- npm install bower -g
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install --production
script:
- bower install --production
- npm run -s build
- bower install
- npm -s test
- npm run -s test
after_success:
- >-
test $TRAVIS_TAG &&
Expand Down
31 changes: 21 additions & 10 deletions bower.json
Expand Up @@ -12,17 +12,28 @@
"url": "git://github.com/purescript-contrib/purescript-profunctor-lenses.git"
},
"dependencies": {
"purescript-const": "^3.0.0",
"purescript-functors": "^2.0.0",
"purescript-foldable-traversable": "^3.4.0",
"purescript-identity": "^3.0.0",
"purescript-profunctor": "^3.0.0",
"purescript-sets": "^3.0.0",
"purescript-unsafe-coerce": "^3.0.0",
"purescript-transformers": "^3.0.0",
"purescript-record": "^0.2.0"
"purescript-arrays": "^5.0.0",
"purescript-bifunctors": "^4.0.0",
"purescript-const": "^4.0.0",
"purescript-control": "^4.0.0",
"purescript-distributive": "^4.0.0",
"purescript-either": "^4.0.0",
"purescript-foldable-traversable": "^4.0.0",
"purescript-foreign-object": "^1.0.0",
"purescript-functors": "^3.0.0",
"purescript-identity": "^4.0.0",
"purescript-lists": "^5.0.0",
"purescript-maybe": "^4.0.0",
"purescript-newtype": "^3.0.0",
"purescript-ordered-collections": "^1.0.0",
"purescript-partial": "^2.0.0",
"purescript-prelude": "^4.0.0",
"purescript-profunctor": "^4.0.0",
"purescript-record": "^1.0.0",
"purescript-transformers": "^4.0.0",
"purescript-tuples": "^5.0.0"
},
"devDependencies": {
"purescript-console": "^3.0.0"
"purescript-console": "^4.0.0"
}
}
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -6,9 +6,8 @@
"test": "pulp test"
},
"devDependencies": {
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.5.4"
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
17 changes: 8 additions & 9 deletions src/Data/Lens/At.purs
Expand Up @@ -7,14 +7,13 @@ module Data.Lens.At
import Prelude

import Data.Identity (Identity(..))
import Data.Lens (Lens', lens)
import Data.Lens.Index (class Index)
import Data.Map as M
import Data.Maybe (Maybe(..), maybe)
import Data.Set as S
import Data.StrMap as SM
import Data.Newtype (unwrap)

import Data.Lens (Lens', lens)
import Data.Lens.Index (class Index)
import Data.Set as S
import Foreign.Object as FO

-- | `At` is a type class whose instances let you add
-- | new elements or delete old ones from "container-like" types:
Expand All @@ -40,7 +39,7 @@ instance atIdentity :: At (Identity a) Unit a where
at _ = lens (Just <<< unwrap) (flip maybe Identity)

instance atMaybe :: At (Maybe a) Unit a where
at _ = lens id \_ -> id
at _ = lens identity \_ -> identity

instance atSet :: Ord v => At (S.Set v) v Unit where
at x = lens get (flip update)
Expand All @@ -57,7 +56,7 @@ instance atMap :: Ord k => At (M.Map k v) k v where
lens (M.lookup k) \m ->
maybe (M.delete k m) \v -> M.insert k v m

instance atStrMap :: At (SM.StrMap v) String v where
instance atForeignObject :: At (FO.Object v) String v where
at k =
lens (SM.lookup k) \m ->
maybe (SM.delete k m) \ v -> SM.insert k v m
lens (FO.lookup k) \m ->
maybe (FO.delete k m) \ v -> FO.insert k v m
41 changes: 20 additions & 21 deletions src/Data/Lens/Fold.purs
Expand Up @@ -16,14 +16,13 @@ import Prelude
import Data.Either (Either(..), either)
import Data.Foldable (class Foldable, foldMap)
import Data.HeytingAlgebra (tt, ff)
import Data.Lens.Internal.Forget (Forget (..))
import Data.Lens.Internal.Forget (Forget(..))
import Data.Lens.Types (Fold, Fold') as ExportTypes
import Data.Lens.Types (IndexedFold, Fold, Optic', Indexed(..))
import Data.List (List(..), (:))
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe.First (First(..))
import Data.Maybe.Last (Last(..))
import Data.Monoid (class Monoid, mempty)
import Data.Monoid.Additive (Additive(..))
import Data.Monoid.Conj (Conj(..))
import Data.Monoid.Disj (Disj(..))
Expand All @@ -47,18 +46,18 @@ infixl 8 previewOn as ^?

-- | Folds all foci of a `Fold` to one. Note that this is the same as `view`.
foldOf :: forall s t a b. Fold a s t a b -> s -> a
foldOf p = foldMapOf p id
foldOf p = foldMapOf p identity

-- | Maps and then folds all foci of a `Fold`.
foldMapOf :: forall s t a b r. Fold r s t a b -> (a -> r) -> s -> r
foldMapOf = under Forget

-- | Right fold over a `Fold`.
foldrOf :: forall s t a b r. Fold (Endo r) s t a b -> (a -> r -> r) -> r -> s -> r
foldrOf :: forall s t a b r. Fold (Endo (->) r) s t a b -> (a -> r -> r) -> r -> s -> r
foldrOf p f r = flip unwrap r <<< foldMapOf p (Endo <<< f)

-- | Left fold over a `Fold`.
foldlOf :: forall s t a b r. Fold (Dual (Endo r)) s t a b -> (r -> a -> r) -> r -> s -> r
foldlOf :: forall s t a b r. Fold (Dual (Endo (->) r)) s t a b -> (r -> a -> r) -> r -> s -> r
foldlOf p f r = flip unwrap r <<< unwrap <<< foldMapOf p (Dual <<< Endo <<< flip f)

-- | Whether all foci of a `Fold` satisfy a predicate.
Expand All @@ -71,11 +70,11 @@ anyOf p f = unwrap <<< foldMapOf p (Disj <<< f)

-- | The conjunction of all foci of a `Fold`.
andOf :: forall s t a b. HeytingAlgebra a => Fold (Conj a) s t a b -> s -> a
andOf p = allOf p id
andOf p = allOf p identity

-- | The disjunction of all foci of a `Fold`.
orOf :: forall s t a b. HeytingAlgebra a => Fold (Disj a) s t a b -> s -> a
orOf p = anyOf p id
orOf p = anyOf p identity

-- | Whether a `Fold` contains a given element.
elemOf :: forall s t a b. Eq a => Fold (Disj Boolean) s t a b -> a -> s -> Boolean
Expand Down Expand Up @@ -106,25 +105,25 @@ lastOf :: forall s t a b. Fold (Last a) s t a b -> s -> Maybe a
lastOf p = unwrap <<< foldMapOf p (Last <<< Just)

-- | The maximum of all foci of a `Fold`, if there is any.
maximumOf :: forall s t a b. Ord a => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
maximumOf :: forall s t a b. Ord a => Fold (Endo (->) (Maybe a)) s t a b -> s -> Maybe a
maximumOf p = foldrOf p (\a -> Just <<< maybe a (max a)) Nothing where
max a b = if a > b then a else b

-- | The minimum of all foci of a `Fold`, if there is any.
minimumOf :: forall s t a b. Ord a => Fold (Endo (Maybe a)) s t a b -> s -> Maybe a
minimumOf :: forall s t a b. Ord a => Fold (Endo (->) (Maybe a)) s t a b -> s -> Maybe a
minimumOf p = foldrOf p (\a -> Just <<< maybe a (min a)) Nothing where
min a b = if a < b then a else b

-- | Find the first focus of a `Fold` that satisfies a predicate, if there is any.
findOf :: forall s t a b. Fold (Endo (Maybe a)) s t a b -> (a -> Boolean) -> s -> Maybe a
findOf :: forall s t a b. Fold (Endo (->) (Maybe a)) s t a b -> (a -> Boolean) -> s -> Maybe a
findOf p f = foldrOf p (\a -> maybe (if f a then Just a else Nothing) Just) Nothing

-- | Sequence the foci of a `Fold`, pulling out an `Applicative`, and ignore
-- | the result. If you need the result, see `sequenceOf` for `Traversal`s.
sequenceOf_
:: forall f s t a b
. Applicative f
=> Fold (Endo (f Unit)) s t (f a) b
=> Fold (Endo (->) (f Unit)) s t (f a) b
-> s
-> f Unit
sequenceOf_ p = flip unwrap (pure unit) <<< foldMapOf p \f -> Endo (f *> _)
Expand All @@ -133,18 +132,18 @@ sequenceOf_ p = flip unwrap (pure unit) <<< foldMapOf p \f -> Endo (f *> _)
traverseOf_
:: forall f s t a b r
. Applicative f
=> Fold (Endo (f Unit)) s t a b
=> Fold (Endo (->) (f Unit)) s t a b
-> (a -> f r)
-> s
-> f Unit
traverseOf_ p f = foldrOf p (\a fu -> void (f a) *> fu) (pure unit)

-- | Collects the foci of a `Fold` into a list.
toListOf :: forall s t a b. Fold (Endo (List a)) s t a b -> s -> List a
toListOf :: forall s t a b. Fold (Endo (->) (List a)) s t a b -> s -> List a
toListOf p = foldrOf p (:) Nil

-- | Synonym for `toListOf`, reversed.
toListOfOn :: forall s t a b. s -> Fold (Endo (List a)) s t a b -> List a
toListOfOn :: forall s t a b. s -> Fold (Endo (->) (List a)) s t a b -> List a
toListOfOn s p = toListOf p s

infixl 8 toListOfOn as ^..
Expand All @@ -163,7 +162,7 @@ filtered f =
right >>>
dimap
(\x -> if f x then Right x else Left x)
(either id id)
(either identity identity)

-- | Replicates the elements of a fold.
replicated :: forall a b t r. Monoid r => Int -> Fold r a b a t
Expand Down Expand Up @@ -198,7 +197,7 @@ ifoldMapOf p f = unwrap $ p $ Indexed $ Forget (uncurry f)
-- | Right fold over an `IndexedFold`.
ifoldrOf
:: forall i s t a b r
. IndexedFold (Endo r) i s t a b
. IndexedFold (Endo (->) r) i s t a b
-> (i -> a -> r -> r)
-> r
-> s
Expand All @@ -208,7 +207,7 @@ ifoldrOf p f r = flip unwrap r <<< ifoldMapOf p (\i -> Endo <<< f i)
-- | Left fold over an `IndexedFold`.
ifoldlOf
:: forall i s t a b r
. IndexedFold (Dual (Endo r)) i s t a b
. IndexedFold (Dual (Endo (->) r)) i s t a b
-> (i -> r -> a -> r)
-> r
-> s
Expand Down Expand Up @@ -242,7 +241,7 @@ ianyOf p f = unwrap <<< ifoldMapOf p (\i -> Disj <<< f i)
-- | there is any.
ifindOf
:: forall i s t a b
. IndexedFold (Endo (Maybe a)) i s t a b
. IndexedFold (Endo (->) (Maybe a)) i s t a b
-> (i -> a -> Boolean)
-> s
-> Maybe a
Expand All @@ -255,15 +254,15 @@ ifindOf p f =
-- | Collects the foci of an `IndexedFold` into a list.
itoListOf
:: forall i s t a b
. IndexedFold (Endo (List (Tuple i a))) i s t a b
. IndexedFold (Endo (->) (List (Tuple i a))) i s t a b
-> s
-> List (Tuple i a)
itoListOf p = ifoldrOf p (\i x xs -> Tuple i x : xs) Nil

-- | Traverse the foci of an `IndexedFold`, discarding the results.
itraverseOf_
:: forall i f s t a b r. (Applicative f)
=> IndexedFold (Endo (f Unit)) i s t a b
=> IndexedFold (Endo (->) (f Unit)) i s t a b
-> (i -> a -> f r)
-> s
-> f Unit
Expand All @@ -272,7 +271,7 @@ itraverseOf_ p f = ifoldrOf p (\i a fu -> void (f i a) *> fu) (pure unit)
-- | Flipped version of `itraverseOf_`.
iforOf_
:: forall i f s t a b r. (Applicative f)
=> IndexedFold (Endo (f Unit)) i s t a b
=> IndexedFold (Endo (->) (f Unit)) i s t a b
-> s
-> (i -> a -> f r)
-> f Unit
Expand Down
6 changes: 3 additions & 3 deletions src/Data/Lens/Getter.purs
Expand Up @@ -18,11 +18,11 @@ infixl 8 viewOn as ^.

-- | View the focus of a `Getter`.
view :: forall s t a b. Getter s t a b -> s -> a
view l = unwrap (l (Forget id))
view l = unwrap (l (Forget identity))

-- | View the focus of a `Getter` and its index.
iview :: forall i s t a b. IndexedFold (Tuple i a) i s t a b -> s -> Tuple i a
iview l = unwrap (l (Indexed $ Forget id))
iview l = unwrap (l (Indexed $ Forget identity))

-- | Synonym for `view`, flipped.
viewOn :: forall s t a b. s -> Getter s t a b -> a
Expand All @@ -34,7 +34,7 @@ to f p = Forget (unwrap p <<< f)

-- | Combine two getters.
takeBoth :: forall s t a b c d. Getter s t a b -> Getter s t c d -> Getter s t (Tuple a c) (Tuple b d)
takeBoth l r a = cmps (l (Forget id)) (r (Forget id))
takeBoth l r a = cmps (l (Forget identity)) (r (Forget identity))
where
cmps :: Forget a s t -> Forget c s t -> Forget (Tuple a c) s t
cmps (Forget f) (Forget g) = Forget (f &&& g)
Expand Down
5 changes: 3 additions & 2 deletions src/Data/Lens/Grate.purs
Expand Up @@ -13,6 +13,7 @@ module Data.Lens.Grate
) where

import Prelude

import Data.Distributive (class Distributive, cotraverse)
import Data.Lens.Internal.Grating (Grating(..))
import Data.Lens.Internal.Zipping (Zipping(..))
Expand All @@ -27,13 +28,13 @@ grate :: forall s t a b. (((s -> a) -> b) -> t) -> Grate s t a b
grate f pab = dimap (#) f (closed pab)

withGrate :: forall s t a b. AGrate s t a b -> ((s -> a) -> b) -> t
withGrate g = unwrap (g (Grating \f -> f id))
withGrate g = unwrap (g (Grating \f -> f identity))

cloneGrate :: forall s t a b. AGrate s t a b -> Grate s t a b
cloneGrate g = grate (withGrate g)

cotraversed :: forall f a b. Distributive f => Grate (f a) (f b) a b
cotraversed = grate \f -> cotraverse f id
cotraversed = grate \f -> cotraverse f identity

zipWithOf :: forall s t a b. Optic Zipping s t a b -> (a -> a -> b) -> s -> s -> t
zipWithOf g f = unwrap (g (Zipping f))
Expand Down
8 changes: 4 additions & 4 deletions src/Data/Lens/Index.purs
Expand Up @@ -12,7 +12,7 @@ import Data.Lens.Types (Traversal')
import Data.Map as M
import Data.Maybe (Maybe, maybe, fromMaybe)
import Data.Set as S
import Data.StrMap as SM
import Foreign.Object as FO
import Data.Traversable (traverse)

-- | `Index` is a type class whose instances are optics used when:
Expand Down Expand Up @@ -80,10 +80,10 @@ instance indexMap :: Ord k => Index (M.Map k v) k v where
(pure m)
(coalg >>> map \v -> M.insert k v m)

instance indexStrMap :: Index (SM.StrMap v) String v where
instance indexForeignObject :: Index (FO.Object v) String v where
ix k =
wander \coalg m ->
SM.lookup k m #
FO.lookup k m #
maybe
(pure m)
(coalg >>> map \v -> SM.insert k v m)
(coalg >>> map \v -> FO.insert k v m)
8 changes: 4 additions & 4 deletions src/Data/Lens/Indexed.purs
Expand Up @@ -9,7 +9,7 @@ import Data.Lens.Iso.Newtype (_Newtype)
import Data.Lens.Setter ((%~))
import Data.Lens.Types (wander, Optic, IndexedOptic, Indexed(..), Traversal, IndexedTraversal)
import Data.Newtype (unwrap)
import Data.Profunctor (class Profunctor, dimap, lmap)
import Data.Profunctor (class Profunctor, dimap, lcmap)
import Data.Profunctor.Star (Star(..))
import Data.Profunctor.Strong (first)
import Data.TraversableWithIndex (class TraversableWithIndex, traverseWithIndex)
Expand All @@ -21,19 +21,19 @@ unIndex
. Profunctor p
=> IndexedOptic p i s t a b
-> Optic p s t a b
unIndex l = l <<< Indexed <<< dimap snd id
unIndex l = l <<< Indexed <<< dimap snd identity

asIndex
:: forall p i s t a b
. Profunctor p
=> IndexedOptic p i s t a b
-> Optic p s t i b
asIndex l = l <<< Indexed <<< dimap fst id
asIndex l = l <<< Indexed <<< dimap fst identity

-- | Remap the index.
reindexed :: forall p i j r a b . Profunctor p =>
(i -> j) -> (Indexed p i a b -> r) -> Indexed p j a b -> r
reindexed ij = (_ <<< _Newtype %~ lmap (first ij))
reindexed ij = (_ <<< _Newtype %~ lcmap (first ij))

-- | Converts a `lens`-like indexed traversal to an `IndexedTraversal`.
iwander
Expand Down
1 change: 0 additions & 1 deletion src/Data/Lens/Internal/Focusing.purs
Expand Up @@ -3,7 +3,6 @@ module Data.Lens.Internal.Focusing where

import Prelude

import Data.Monoid (class Monoid)
import Data.Tuple (Tuple)
import Data.Newtype (class Newtype)

Expand Down

0 comments on commit 54138b0

Please sign in to comment.