-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from pbrant/add-atraversal
Add ATraversal and cloneTraversal
- Loading branch information
Showing
4 changed files
with
54 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Data.Lens.Internal.Bazaar where | ||
|
||
import Prelude | ||
|
||
import Data.Bitraversable (bitraverse) | ||
import Data.Lens.Internal.Wander (class Wander) | ||
import Data.Profunctor (class Profunctor) | ||
import Data.Profunctor.Choice (class Choice) | ||
import Data.Profunctor.Strong (class Strong) | ||
import Data.Traversable (traverse) | ||
import Data.Tuple (Tuple(..)) | ||
|
||
-- | This is used to characterize a Traversal. | ||
newtype Bazaar p a b s t = Bazaar (forall f. Applicative f => p a (f b) -> s -> f t) | ||
|
||
runBazaar :: forall p a b s t. Bazaar p a b s t -> (forall f. Applicative f => p a (f b) -> s -> f t) | ||
runBazaar (Bazaar x) = x | ||
|
||
instance profunctorBazaar :: Profunctor (Bazaar p a b) where | ||
dimap f g (Bazaar b) = Bazaar \pafb s -> g <$> b pafb (f s) | ||
|
||
instance strongBazaar :: Strong (Bazaar p a b) where | ||
first (Bazaar b) = Bazaar (\pafb (Tuple x y) -> flip Tuple y <$> b pafb x) | ||
second (Bazaar b) = Bazaar (\pafb (Tuple x y) -> Tuple x <$> b pafb y) | ||
|
||
instance choiceBazaar :: Choice (Bazaar p a b) where | ||
left (Bazaar b) = Bazaar (\pafb e -> bitraverse (b pafb) pure e) | ||
right (Bazaar b) = Bazaar (\pafb e -> traverse (b pafb) e) | ||
|
||
instance wanderBazaar :: Wander (Bazaar p a b) where | ||
wander w (Bazaar f) = Bazaar (\pafb s -> w (f pafb) s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters