Skip to content

Commit a327baf

Browse files
committed
Add asIndex
Takes an IndexedOptic to an Optic over the indices. For example: toListOf (asIndex (positions traversed)) [1, 2, 3] -- (0 : 1 : 2 : Nil)
1 parent 1e1547d commit a327baf

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Data/Lens/Indexed.purs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Data.Lens.Types (class Wander, wander, IndexedOptic, Traversal, Optic, In
99
import Data.Newtype (unwrap)
1010
import Data.Profunctor (class Profunctor, dimap)
1111
import Data.Profunctor.Star (Star(..))
12-
import Data.Tuple (curry, snd)
12+
import Data.Tuple (curry, fst, snd)
1313

1414
-- | Converts an `IndexedOptic` to an `Optic` by forgetting indices.
1515
unIndex
@@ -19,6 +19,13 @@ unIndex
1919
-> Optic p s t a b
2020
unIndex l = l <<< Indexed <<< dimap snd id
2121

22+
asIndex
23+
:: forall p i s t a b
24+
. Profunctor p
25+
=> IndexedOptic p i s t a b
26+
-> Optic p s t i b
27+
asIndex l = l <<< Indexed <<< dimap fst id
28+
2229
-- | Converts a `lens`-like indexed traversal to an `IndexedTraversal`.
2330
iwander
2431
:: forall p i s t a b

0 commit comments

Comments
 (0)