File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import Data.Array.NonEmpty as NEA
10
10
import Data.Identity (Identity )
11
11
import Data.Lens.Internal.Wander (wander )
12
12
import Data.Lens.Types (Traversal' )
13
+ import Data.List (List (..), (:))
13
14
import Data.Map as M
14
15
import Data.Maybe (Maybe , maybe , fromMaybe )
15
16
import Data.Set as S
@@ -76,6 +77,14 @@ instance indexNonEmptyArray :: Index (NEA.NonEmptyArray a) Int a where
76
77
(pure xs)
77
78
(coalg >>> map \x -> fromMaybe xs (NEA .updateAt n x xs))
78
79
80
+ instance indexList :: Index (List a ) Int a where
81
+ ix n | n < 0 = wander \_ xs -> pure xs
82
+ | otherwise = wander \coalg xs -> go xs n coalg where
83
+ go :: forall f . Applicative f => List a -> Int -> (a -> f a ) -> f (List a )
84
+ go Nil _ _ = pure Nil
85
+ go (a:as) 0 coalg = coalg a <#> (_:as)
86
+ go (a:as) i coalg = (a:_) <$> (go as (i - 1 ) coalg)
87
+
79
88
instance indexSet :: Ord a => Index (S.Set a ) a Unit where
80
89
ix x =
81
90
wander \coalg ->
You can’t perform that action at this time.
0 commit comments