Skip to content

Commit

Permalink
Merge pull request #41 from purescript-contrib/bump
Browse files Browse the repository at this point in the history
Prepare for 2.0 release
  • Loading branch information
garyb authored Oct 22, 2016
2 parents be6ecac + 1b695c2 commit 1e1547d
Show file tree
Hide file tree
Showing 31 changed files with 266 additions and 298 deletions.
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ language: node_js
dist: trusty
sudo: required
node_js: 6
env:
- PATH=$HOME/purescript:$PATH
install:
- 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 -g
- npm install
script:
- bower install --production
script:
- npm run -s build
- bower install
- npm -s test
Expand Down
17 changes: 8 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
"url": "git://github.com/purescript-contrib/purescript-profunctor-lenses.git"
},
"dependencies": {
"purescript-const": "^1.0.0",
"purescript-functor-coproducts": "^1.0.0",
"purescript-functor-products": "^1.0.0",
"purescript-identity": "^1.0.0",
"purescript-profunctor": "^1.0.0",
"purescript-sets": "^1.0.0",
"purescript-unsafe-coerce": "^1.0.0",
"purescript-transformers": "^1.0.0"
"purescript-const": "^2.0.0",
"purescript-functors": "^1.0.0",
"purescript-identity": "^2.0.0",
"purescript-profunctor": "^2.0.0",
"purescript-sets": "^2.0.0",
"purescript-unsafe-coerce": "^2.0.0",
"purescript-transformers": "^2.0.1"
},
"devDependencies": {
"purescript-console": "^1.0.0"
"purescript-console": "^2.0.0"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"devDependencies": {
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.0"
"purescript": "^0.10.1",
"rimraf": "^2.5.4"
}
}
14 changes: 7 additions & 7 deletions src/Data/Lens.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ module Data.Lens
, module Data.Lens.Common
) where

import Data.Lens.Iso (AnIso, AnIsoP, Iso, IsoP, Optic, Exchange(..), Re(..), au, auf, cloneIso, curried, flipped, iso, re, runRe, uncurried, under, withIso)
import Data.Lens.Lens (ALens, ALensP, Lens, LensP, cloneLens, lens, lens', withLens)
import Data.Lens.Prism (APrism, APrismP, Prism, PrismP, Review, ReviewP, clonePrism, is, isn't, matching, nearly, only, prism, prism', review, withPrism)
import Data.Lens.Traversal (Traversal, TraversalP, element, elementsOf, failover, itraverseOf, sequenceOf, traverseOf, traversed)
import Data.Lens.Types
import Data.Lens.Setter (IndexedSetter, Setter, SetterP, Indexed(..), addModifying, addOver, appendModifying, appendOver, assign, assignJust, conjModifying, conjOver, disjModifying, disjOver, divModifying, divOver, iover, modifying, mulModifying, mulOver, over, set, setJust, subModifying, subOver, (%=), (%~), (&&=), (&&~), (*=), (*~), (++=), (++~), (+=), (+~), (-=), (-~), (.=), (.~), (//=), (//~), (<>=), (<>~), (?=), (?~), (||=), (||~))
import Data.Lens.Iso (AnIso, AnIso', Iso, Iso', Optic, Exchange(..), Re(..), au, auf, cloneIso, curried, flipped, iso, re, uncurried, under, withIso)
import Data.Lens.Lens (ALens, ALens', Lens, Lens', cloneLens, lens, lens', withLens)
import Data.Lens.Prism (APrism, APrism', Prism, Prism', Review, Review', clonePrism, is, isn't, matching, nearly, only, prism, prism', review, withPrism)
import Data.Lens.Traversal (Traversal, Traversal', element, elementsOf, failover, itraverseOf, sequenceOf, traverseOf, traversed)
import Data.Lens.Types (class Wander, ALens, ALens', APrism, APrism', AnIso, AnIso', Fold, Fold', Getter, Getter', IndexedFold, IndexedFold', IndexedGetter, IndexedGetter', IndexedOptic, IndexedOptic', IndexedSetter, IndexedSetter', IndexedTraversal, IndexedTraversal', Iso, Iso', Lens, Lens', Optic, Optic', Prism, Prism', Review, Review', Setter, Setter', Traversal, Traversal', Exchange(..), Forget(..), Indexed(..), Market(..), Re(..), Shop(..), Tagged(..), wander)
import Data.Lens.Setter (IndexedSetter, Setter, Setter', Indexed(..), addModifying, addOver, appendModifying, appendOver, assign, assignJust, conjModifying, conjOver, disjModifying, disjOver, divModifying, divOver, iover, modifying, mulModifying, mulOver, over, set, setJust, subModifying, subOver, (%=), (%~), (&&=), (&&~), (*=), (*~), (++=), (++~), (+=), (+~), (-=), (-~), (.=), (.~), (//=), (//~), (<>=), (<>~), (?=), (?~), (||=), (||~))
import Data.Lens.Getter (Fold, Getter, IndexedFold, IndexedGetter, Optic, Indexed(..), iuse, iview, to, use, view, viewOn, (^.))
import Data.Lens.Fold (Fold, FoldP, allOf, andOf, anyOf, elemOf, filtered, findOf, firstOf, foldMapOf, foldOf, folded, foldlOf, foldrOf, has, hasn't, iallOf, ianyOf, ifoldMapOf, ifoldlOf, ifoldrOf, itoListOf, itraverseOf_, lastOf, lengthOf, maximumOf, minimumOf, notElemOf, orOf, preview, previewOn, productOf, replicated, sequenceOf_, sumOf, toListOf, toListOfOn, unfolded, (^..), (^?))
import Data.Lens.Fold (Fold, Fold', allOf, andOf, anyOf, elemOf, filtered, findOf, firstOf, foldMapOf, foldOf, folded, foldlOf, foldrOf, has, hasn't, iallOf, ianyOf, ifoldMapOf, ifoldlOf, ifoldrOf, itoListOf, itraverseOf_, lastOf, lengthOf, maximumOf, minimumOf, notElemOf, orOf, preview, previewOn, productOf, replicated, sequenceOf_, sumOf, toListOf, toListOfOn, unfolded, (^..), (^?))
import Data.Lens.Common (_1, _2, _Just, _Left, _Nothing, _Right, first, left, right, second, united)
15 changes: 8 additions & 7 deletions src/Data/Lens/At.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ module Data.Lens.At

import Prelude

import Data.Identity (runIdentity, Identity(..))
import Data.Identity (Identity(..))
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 (LensP, lens)
import Data.Lens (Lens', lens)
import Data.Lens.Index (class Index)

class (Index m a b) <= At m a b where
at :: a -> LensP m (Maybe b)
class Index m a b <= At m a b | m -> a, m -> b where
at :: a -> Lens' m (Maybe b)

instance atIdentity :: At (Identity a) Unit a where
at _ = lens (Just <<< runIdentity) (flip maybe Identity)
at _ = lens (Just <<< unwrap) (flip maybe Identity)

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

instance atSet :: (Ord v) => At (S.Set v) v Unit where
instance atSet :: Ord v => At (S.Set v) v Unit where
at x = lens get (flip update)
where
get xs =
Expand All @@ -33,7 +34,7 @@ instance atSet :: (Ord v) => At (S.Set v) v Unit where
update Nothing = S.delete x
update (Just _) = S.insert x

instance atMap :: (Ord k) => At (M.Map k v) k v where
instance atMap :: Ord k => At (M.Map k v) k v where
at k =
lens (M.lookup k) \m ->
maybe (M.delete k m) \v -> M.insert k v m
Expand Down
99 changes: 51 additions & 48 deletions src/Data/Lens/Fold.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,36 @@ module Data.Lens.Fold
, folded, unfolded
, ifoldMapOf, ifoldrOf, ifoldlOf, iallOf, ianyOf, itoListOf, itraverseOf_
, module ExportTypes
) where
)
where

import Prelude

import Data.Either (Either(..), either)
import Data.Foldable (class Foldable, foldMap)
import Data.HeytingAlgebra (tt, ff)
import Data.Lens.Internal.Forget (Forget (..), runForget)
import Data.Lens.Types (Fold, FoldP) as ExportTypes
import Data.Lens.Types (IndexedFold, Fold, OpticP, Indexed(..))
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(..), runFirst)
import Data.Maybe.Last (Last(..), runLast)
import Data.Maybe.First (First(..))
import Data.Maybe.Last (Last(..))
import Data.Monoid (class Monoid, mempty)
import Data.Monoid.Additive (Additive(..), runAdditive)
import Data.Monoid.Conj (Conj(..), runConj)
import Data.Monoid.Disj (Disj(..), runDisj)
import Data.Monoid.Dual (Dual(..), runDual)
import Data.Monoid.Endo (Endo(..), runEndo)
import Data.Monoid.Multiplicative (Multiplicative(..), runMultiplicative)
import Data.Monoid.Additive (Additive(..))
import Data.Monoid.Conj (Conj(..))
import Data.Monoid.Disj (Disj(..))
import Data.Monoid.Dual (Dual(..))
import Data.Monoid.Endo (Endo(..))
import Data.Monoid.Multiplicative (Multiplicative(..))
import Data.Newtype (unwrap, under)
import Data.Profunctor (dimap)
import Data.Profunctor.Choice (class Choice, right)
import Data.Tuple (Tuple(..), uncurry)

-- | Previews the first value of a fold, if there is any.
preview :: forall s t a b. Fold (First a) s t a b -> s -> Maybe a
preview p = runFirst <<< foldMapOf p (First <<< Just)
preview p = unwrap <<< foldMapOf p (First <<< Just)

-- | Synonym for `preview`, flipped.
previewOn :: forall s t a b. s -> Fold (First a) s t a b -> Maybe a
Expand All @@ -45,71 +47,71 @@ 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 = runForget (p (Forget id))
foldOf p = foldMapOf p id

-- | 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 p f = runForget (p (Forget f))
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 p f r = flip runEndo r <<< foldMapOf p (Endo <<< f)
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 p f r = flip runEndo r <<< runDual <<< foldMapOf p (Dual <<< Endo <<< flip f)
foldlOf p f r = flip unwrap r <<< unwrap <<< foldMapOf p (Dual <<< Endo <<< flip f)

-- | Whether all foci of a `Fold` satisfy a predicate.
allOf :: forall s t a b r. (BooleanAlgebra r) => Fold (Conj r) s t a b -> (a -> r) -> s -> r
allOf p f = runConj <<< foldMapOf p (Conj <<< f)
allOf :: forall s t a b r. HeytingAlgebra r => Fold (Conj r) s t a b -> (a -> r) -> s -> r
allOf p f = unwrap <<< foldMapOf p (Conj <<< f)

-- | Whether any focus of a `Fold` satisfies a predicate.
anyOf :: forall s t a b r. (BooleanAlgebra r) => Fold (Disj r) s t a b -> (a -> r) -> s -> r
anyOf p f = runDisj <<< foldMapOf p (Disj <<< f)
anyOf :: forall s t a b r. HeytingAlgebra r => Fold (Disj r) s t a b -> (a -> r) -> s -> r
anyOf p f = unwrap <<< foldMapOf p (Disj <<< f)

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

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

-- | 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
elemOf :: forall s t a b. Eq a => Fold (Disj Boolean) s t a b -> a -> s -> Boolean
elemOf p a = anyOf p (_ == a)

-- | Whether a `Fold` not contains a given element.
notElemOf :: forall s t a b. (Eq a) => Fold (Conj Boolean) s t a b -> a -> s -> Boolean
notElemOf :: forall s t a b. Eq a => Fold (Conj Boolean) s t a b -> a -> s -> Boolean
notElemOf p a = allOf p (_ /= a)

-- | The sum of all foci of a `Fold`.
sumOf :: forall s t a b. (Semiring a) => Fold (Additive a) s t a b -> s -> a
sumOf p = runAdditive <<< foldMapOf p Additive
sumOf :: forall s t a b. Semiring a => Fold (Additive a) s t a b -> s -> a
sumOf p = unwrap <<< foldMapOf p Additive

-- | The product of all foci of a `Fold`.
productOf :: forall s t a b. (Semiring a) => Fold (Multiplicative a) s t a b -> s -> a
productOf p = runMultiplicative <<< foldMapOf p Multiplicative
productOf :: forall s t a b. Semiring a => Fold (Multiplicative a) s t a b -> s -> a
productOf p = unwrap <<< foldMapOf p Multiplicative

-- | The number of foci of a `Fold`.
lengthOf :: forall s t a b. Fold (Additive Int) s t a b -> s -> Int
lengthOf p = runAdditive <<< foldMapOf p (const $ Additive 1)
lengthOf p = unwrap <<< foldMapOf p (const $ Additive 1)

-- | The first focus of a `Fold`, if there is any. Synonym for `preview`.
firstOf :: forall s t a b. Fold (First a) s t a b -> s -> Maybe a
firstOf p = runFirst <<< foldMapOf p (First <<< Just)
firstOf p = unwrap <<< foldMapOf p (First <<< Just)

-- | The last focus of a `Fold`, if there is any.
lastOf :: forall s t a b. Fold (Last a) s t a b -> s -> Maybe a
lastOf p = runLast <<< foldMapOf p (Last <<< Just)
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

Expand All @@ -125,7 +127,7 @@ sequenceOf_
=> Fold (Endo (f Unit)) s t (f a) b
-> s
-> f Unit
sequenceOf_ p = flip runEndo (pure unit) <<< foldMapOf p \f -> Endo (f *> _)
sequenceOf_ p = flip unwrap (pure unit) <<< foldMapOf p \f -> Endo (f *> _)

-- | Traverse the foci of a `Fold`, discarding the results.
traverseOf_
Expand All @@ -149,29 +151,30 @@ infixl 8 toListOfOn as ^..

-- | Determines whether a `Fold` has at least one focus.
has :: forall s t a b r. HeytingAlgebra r => Fold (Disj r) s t a b -> s -> r
has p = runDisj <<< foldMapOf p (const (Disj tt))
has p = unwrap <<< foldMapOf p (const (Disj tt))

-- | Determines whether a `Fold` does not have a focus.
hasn't :: forall s t a b r. HeytingAlgebra r => Fold (Conj r) s t a b -> s -> r
hasn't p = runConj <<< foldMapOf p (const (Conj ff))
hasn't p = unwrap <<< foldMapOf p (const (Conj ff))

-- | Filters on a predicate.
filtered :: forall p a. (Choice p) => (a -> Boolean) -> OpticP p a a
filtered :: forall p a. Choice p => (a -> Boolean) -> Optic' p a a
filtered f =
right >>>
dimap
(\x -> if f x then Right x else Left x)
(either id id)

-- | Replicates the elements of a fold.
replicated :: forall a b t r. (Monoid r) => Int -> Fold r a b a t
replicated n = Forget <<< go n <<< runForget where
replicated :: forall a b t r. Monoid r => Int -> Fold r a b a t
replicated i (Forget a) = Forget (go i a)
where
go 0 x = mempty
go n x = x <> go (n - 1) x

-- | Folds over a `Foldable` container.
folded :: forall g a b t r. (Monoid r, Foldable g) => Fold r (g a) b a t
folded = Forget <<< foldMap <<< runForget
folded (Forget a) = Forget (foldMap a)

-- | Builds a `Fold` using an unfold.
unfolded
Expand All @@ -181,7 +184,7 @@ unfolded
-> Fold r s t a b
unfolded f p = Forget go
where
go = maybe mempty (\(Tuple a sn) -> runForget p a <> go sn) <<< f
go = maybe mempty (\(Tuple a sn) -> unwrap p a <> go sn) <<< f

-- | Fold map over an `IndexedFold`.
ifoldMapOf
Expand All @@ -190,7 +193,7 @@ ifoldMapOf
-> (i -> a -> r)
-> s
-> r
ifoldMapOf p f = runForget $ p $ Indexed $ Forget (uncurry f)
ifoldMapOf p f = unwrap $ p $ Indexed $ Forget (uncurry f)

-- | Right fold over an `IndexedFold`.
ifoldrOf
Expand All @@ -200,7 +203,7 @@ ifoldrOf
-> r
-> s
-> r
ifoldrOf p f r = flip runEndo r <<< ifoldMapOf p (\i -> Endo <<< f i)
ifoldrOf p f r = flip unwrap r <<< ifoldMapOf p (\i -> Endo <<< f i)

-- | Left fold over an `IndexedFold`.
ifoldlOf
Expand All @@ -211,8 +214,8 @@ ifoldlOf
-> s
-> r
ifoldlOf p f r =
flip runEndo r
<<< runDual
flip unwrap r
<<< unwrap
<<< ifoldMapOf p (\i -> Dual <<< Endo <<< flip (f i))

-- | Whether all foci of an `IndexedFold` satisfy a predicate.
Expand All @@ -223,7 +226,7 @@ iallOf
-> (i -> a -> r)
-> s
-> r
iallOf p f = runConj <<< ifoldMapOf p (\i -> Conj <<< f i)
iallOf p f = unwrap <<< ifoldMapOf p (\i -> Conj <<< f i)

-- | Whether any focus of an `IndexedFold` satisfies a predicate.
ianyOf
Expand All @@ -233,7 +236,7 @@ ianyOf
-> (i -> a -> r)
-> s
-> r
ianyOf p f = runDisj <<< ifoldMapOf p (\i -> Disj <<< f i)
ianyOf p f = unwrap <<< ifoldMapOf p (\i -> Disj <<< f i)

-- | Find the first focus of an `IndexedFold` that satisfies a predicate, if
-- | there is any.
Expand Down
Loading

0 comments on commit 1e1547d

Please sign in to comment.