@@ -50,7 +50,7 @@ import Data.Int (Int, Int64)
50
50
import GHC.Exts (build )
51
51
import Prelude (Bool (.. ), Bounded (.. ), const , Char , Enum (.. ), flip , IO , Maybe (.. ), Either (.. ),
52
52
(+) , Integral , Ordering (.. ), compare , fromIntegral , Num , (>=) ,
53
- (==) , seq , otherwise , Eq , Ord , (-) , (*) , uncurry , ($) )
53
+ (==) , seq , otherwise , Eq , Ord , (-) , (*) , uncurry , ($) , snd )
54
54
import qualified Prelude
55
55
import qualified Data.ByteString.Internal as Unsafe
56
56
import qualified Foreign.ForeignPtr.Unsafe as Unsafe
@@ -73,7 +73,7 @@ import Data.HashMap.Strict (HashMap)
73
73
import qualified Data.HashMap.Strict as HM
74
74
import Data.Vector (Vector )
75
75
import Control.Monad.Trans.Maybe (MaybeT (.. ))
76
- import Control.Monad.Trans.List (ListT )
76
+ import Control.Monad.Trans.List (ListT ( .. ) )
77
77
import Control.Monad.Trans.Writer (WriterT )
78
78
import qualified Control.Monad.Trans.Writer.Strict as S (WriterT )
79
79
import Control.Monad.Trans.State (StateT (.. ))
@@ -101,7 +101,7 @@ import Data.Void
101
101
import Control.Monad.Trans.Identity (IdentityT )
102
102
import GHC.Generics
103
103
import Data.MonoTraversable (Element , MonoFunctor (.. ), MonoFoldable (.. ), MonoTraversable (.. ))
104
-
104
+ import Data.Vector.Instances
105
105
106
106
-- |
107
107
-- Type family for getting the type of the key of a monomorphic container.
@@ -423,34 +423,48 @@ instance (Traversable f, Traversable g) => MonoTraversableWithKey (Compose f g a
423
423
instance (Traversable f , Traversable g ) => MonoTraversableWithKey (Product f g a )
424
424
425
425
426
- instance MonoKeyed BS. ByteString where
426
+ omapWithUnitKey f = omap (f () )
427
427
428
+
429
+ instance MonoKeyed BS. ByteString where
428
430
{-# INLINE omapWithKey #-}
429
- omapWithKey = BS. map
430
431
432
+ omapWithKey f = snd . BS. mapAccumL g 0
433
+ where
434
+ g k v = (succ k, f k v)
431
435
432
- instance MonoKeyed BSL. ByteString where
433
436
437
+ instance MonoKeyed BSL. ByteString where
434
438
{-# INLINE omapWithKey #-}
435
- omapWithKey = BSL. map
436
439
440
+ omapWithKey f = snd . BSL. mapAccumL g 0
441
+ where
442
+ g k v = (succ k, f k v)
437
443
438
- instance MonoKeyed T. Text where
439
444
445
+ instance MonoKeyed T. Text where
440
446
{-# INLINE omapWithKey #-}
441
- omapWithKey = T. map
442
447
448
+ omapWithKey f = snd . T. mapAccumL g 0
449
+ where
450
+ g k v = (succ k, f k v)
443
451
444
- instance MonoKeyed TL. Text where
445
452
453
+ instance MonoKeyed TL. Text where
446
454
{-# INLINE omapWithKey #-}
447
- omapWithKey = TL. map
455
+
456
+ omapWithKey f = snd . TL. mapAccumL g 0
457
+ where
458
+ g k v = (succ k, f k v)
448
459
449
460
450
461
instance MonoKeyed [a ]
451
462
452
463
453
- instance MonoKeyed (IO a )
464
+ instance MonoKeyed (IO a ) where
465
+ {-# INLINE omapWithKey #-}
466
+
467
+ omapWithKey = omapWithUnitKey
454
468
455
469
456
470
instance MonoKeyed (ZipList a )
@@ -465,16 +479,25 @@ instance MonoKeyed (Tree a)
465
479
instance MonoKeyed (Seq a )
466
480
467
481
468
- instance MonoKeyed (ViewL a )
482
+ instance MonoKeyed (ViewL a ) where
483
+ {-# INLINE omapWithKey #-}
484
+
485
+ omapWithKey = omapWithUnitKey
486
+
469
487
488
+ instance MonoKeyed (ViewR a ) where
489
+ {-# INLINE omapWithKey #-}
470
490
471
- instance MonoKeyed ( ViewR a )
491
+ omapWithKey = omapWithUnitKey
472
492
473
493
474
494
instance MonoKeyed (IntMap a )
475
495
476
496
477
- instance MonoKeyed (Option a )
497
+ instance MonoKeyed (Option a ) where
498
+ {-# INLINE omapWithKey #-}
499
+
500
+ omapWithKey = omapWithUnitKey
478
501
479
502
480
503
instance MonoKeyed (NonEmpty a )
@@ -483,19 +506,34 @@ instance MonoKeyed (NonEmpty a)
483
506
instance MonoKeyed (Identity a )
484
507
485
508
486
- instance MonoKeyed (r -> a )
509
+ instance MonoKeyed (r -> a ) where
510
+ {-# INLINE omapWithKey #-}
487
511
512
+ omapWithKey = omapWithUnitKey
488
513
489
- instance MonoKeyed (Either a b )
490
514
515
+ instance MonoKeyed (Either a b ) where
516
+ {-# INLINE omapWithKey #-}
491
517
492
- instance MonoKeyed ( a , b )
518
+ omapWithKey = omapWithUnitKey
493
519
494
520
495
- instance MonoKeyed (Const m a )
521
+ instance MonoKeyed (a , b ) where
522
+ {-# INLINE omapWithKey #-}
496
523
524
+ omapWithKey = omapWithUnitKey
497
525
498
- instance Monad m => MonoKeyed (WrappedMonad m a )
526
+
527
+ instance MonoKeyed (Const m a ) where
528
+ {-# INLINE omapWithKey #-}
529
+
530
+ omapWithKey = omapWithUnitKey
531
+
532
+
533
+ instance Monad m => MonoKeyed (WrappedMonad m a ) where
534
+ {-# INLINE omapWithKey #-}
535
+
536
+ omapWithKey = omapWithUnitKey
499
537
500
538
501
539
instance MonoKeyed (Map k v )
@@ -507,49 +545,94 @@ instance MonoKeyed (HashMap k v)
507
545
instance MonoKeyed (Vector a )
508
546
509
547
510
- instance MonoKeyed (Arg a b )
548
+ instance MonoKeyed (Arg a b ) where
549
+ {-# INLINE omapWithKey #-}
511
550
551
+ omapWithKey = omapWithUnitKey
512
552
513
- instance Arrow a => MonoKeyed (WrappedArrow a b c )
514
553
554
+ instance Arrow a => MonoKeyed (WrappedArrow a b c ) where
555
+ {-# INLINE omapWithKey #-}
515
556
516
- instance Functor m => MonoKeyed ( MaybeT m a )
557
+ omapWithKey = omapWithUnitKey
517
558
518
559
519
- instance Functor m => MonoKeyed (ListT m a )
560
+ instance Functor m => MonoKeyed (MaybeT m a ) where
561
+ {-# INLINE omapWithKey #-}
520
562
563
+ omapWithKey = omapWithUnitKey
521
564
522
- instance Functor m => MonoKeyed (IdentityT m a )
523
565
566
+ instance Functor m => MonoKeyed (ListT m a ) where
567
+ {-# INLINE omapWithKey #-}
524
568
525
- instance Functor m => MonoKeyed ( WriterT w m a )
569
+ omapWithKey f = ListT . fmap (omapWithKey f) . runListT
526
570
527
571
528
- instance Functor m => MonoKeyed (S. WriterT w m a )
572
+ instance Functor m => MonoKeyed (IdentityT m a ) where
573
+ {-# INLINE omapWithKey #-}
529
574
575
+ omapWithKey = omapWithUnitKey
530
576
531
- instance Functor m => MonoKeyed (StateT s m a )
532
577
578
+ instance Functor m => MonoKeyed (WriterT w m a ) where
579
+ {-# INLINE omapWithKey #-}
533
580
534
- instance Functor m => MonoKeyed ( S. StateT s m a )
581
+ omapWithKey = omapWithUnitKey
535
582
536
583
537
- instance Functor m => MonoKeyed (RWST r w s m a )
584
+ instance Functor m => MonoKeyed (S. WriterT w m a ) where
585
+ {-# INLINE omapWithKey #-}
538
586
587
+ omapWithKey = omapWithUnitKey
539
588
540
- instance Functor m => MonoKeyed (S. RWST r w s m a )
541
589
590
+ instance Functor m => MonoKeyed (StateT s m a ) where
591
+ {-# INLINE omapWithKey #-}
542
592
543
- instance Functor m => MonoKeyed ( ReaderT r m a )
593
+ omapWithKey = omapWithUnitKey
544
594
545
595
546
- instance Functor m => MonoKeyed (ContT r m a )
596
+ instance Functor m => MonoKeyed (S. StateT s m a ) where
597
+ {-# INLINE omapWithKey #-}
547
598
599
+ omapWithKey = omapWithUnitKey
600
+
601
+
602
+ instance Functor m => MonoKeyed (RWST r w s m a ) where
603
+ {-# INLINE omapWithKey #-}
604
+
605
+ omapWithKey = omapWithUnitKey
606
+
607
+
608
+ instance Functor m => MonoKeyed (S. RWST r w s m a ) where
609
+ {-# INLINE omapWithKey #-}
548
610
549
- instance ( Functor f , Functor g ) => MonoKeyed ( Compose f g a )
611
+ omapWithKey = omapWithUnitKey
550
612
551
613
552
- instance (Functor f , Functor g ) => MonoKeyed (Product f g a )
614
+ instance Functor m => MonoKeyed (ReaderT r m a ) where
615
+ {-# INLINE omapWithKey #-}
616
+
617
+ omapWithKey = omapWithUnitKey
618
+
619
+
620
+ instance Functor m => MonoKeyed (ContT r m a ) where
621
+ {-# INLINE omapWithKey #-}
622
+
623
+ omapWithKey = omapWithUnitKey
624
+
625
+
626
+ instance (Functor f , Functor g ) => MonoKeyed (Compose f g a ) where
627
+ {-# INLINE omapWithKey #-}
628
+
629
+ omapWithKey = omapWithUnitKey
630
+
631
+
632
+ instance (Functor f , Functor g ) => MonoKeyed (Product f g a ) where
633
+ {-# INLINE omapWithKey #-}
634
+
635
+ omapWithKey = omapWithUnitKey
553
636
554
637
555
638
instance U. Unbox a => MonoKeyed (U. Vector a ) where
0 commit comments