Skip to content

Commit 885f931

Browse files
xgrommxJordanMartinezthomashoneyman
authored
Several combinators (#97)
* Added `both` * Added `sans` * Update changelog * Update src/Data/Lens/Traversal.purs Co-authored-by: Thomas Honeyman <[email protected]> * Use `set` rather than `.~` Co-authored-by: JordanMartinez <[email protected]> Co-authored-by: Thomas Honeyman <[email protected]>
1 parent 6eb23ee commit 885f931

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Add `sans` and `both` (#97 by @xgrommx)
1011

1112
Bugfixes:
1213

src/Data/Lens/At.purs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module Data.Lens.At
22
( class At
33
, at
4+
, sans
45
) where
56

67

78
import Prelude
89

910
import Data.Identity (Identity(..))
10-
import Data.Lens (Lens', lens)
11+
import Data.Lens (Lens', lens, set)
1112
import Data.Lens.Index (class Index)
1213
import Data.Map as M
1314
import Data.Maybe (Maybe(..), maybe, maybe')
@@ -60,3 +61,6 @@ instance atForeignObject :: At (FO.Object v) String v where
6061
at k =
6162
lens (FO.lookup k) \m ->
6263
maybe' (\_ -> FO.delete k m) \v -> FO.insert k v m
64+
65+
sans :: forall m a b. At m a b => a -> m -> m
66+
sans k = at k `set` Nothing

src/Data/Lens/Traversal.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ module Data.Lens.Traversal
2727
, itraverseOf
2828
, iforOf
2929
, cloneTraversal
30+
, both
3031
, module ExportTypes
3132
) where
3233

3334
import Prelude
3435

3536
import Control.Alternative (class Alternative)
3637
import Control.Plus (empty)
38+
import Data.Bitraversable (class Bitraversable, bitraverse)
3739
import Data.Lens.Indexed (iwander, positions, unIndex)
3840
import Data.Lens.Internal.Bazaar (Bazaar(..), runBazaar)
3941
import Data.Lens.Types (ATraversal, IndexedTraversal, IndexedOptic, Indexed(..), Traversal, Optic, class Wander, wander)
@@ -147,3 +149,6 @@ iforOf = flip <<< itraverseOf
147149

148150
cloneTraversal :: forall s t a b. ATraversal s t a b -> Traversal s t a b
149151
cloneTraversal l = wander (runBazaar (l (Bazaar identity)))
152+
153+
both :: forall r a b. Bitraversable r => Traversal (r a a) (r b b) a b
154+
both = wander (join bitraverse)

0 commit comments

Comments
 (0)