úÎ!N`LŠ     blah(c) David James, 2020 BSD3  Experimental SafeEXK MapWithAn  is (recursively) either: a function  (a -> i -> b); oran InjectedFn a (i -> b) , created by  op MapWithInject "from the left"MapWithInject "from the right"MapWithRepresents a function from a', plus a number of injected values, to b.Used by   (& related), which maps over a -, injecting the additional values as it goes..Constructed by combining a map function with  s using the  and  operators. The sequence: "(a -> i1 -> i2 -> ... -> in -> b) op1 inj1 op2 inj2 ... opn injnwhere:each op is  or ; andeach inj is an  produces an  a b, with n injected values.MapWith8Injectors have an initial state and a generate function.For each item in the %, the generate function can use both:the item from the , andthe current stateto determine both:the injection value, andthe new state. The first value to inject is determined by a first call to the generate function. The first call to the generate function is with the first (if combined with ) or last (if combined with ) item from the  and the initial state. For example:funnyNext a s = (a + s, a + 1)%funnyInjector = Injector funnyNext 17/mapWith ((\_ i -> i) ^-> funnyInjector) [4,8,3] [21,13,12] Call  Initial State  Item  Injection  New State  1  17  4  17+4=21  4+1=5  2  5  8  5+8=13  8+1=9  3  9  3  9+3=12  3+1=4 (ignored) /mapWith ((\_ i -> i) <-^ funnyInjector) [4,8,3] [13,12,20] Call  Initial State  Item  Injection  New State  1  17  3  17+3=20  3+1=4  2  4  8  4+8=12  8+1=9  3  9  4  9+4=13  4+1=5 (ignored) @More usefully, this would allow for e.g. the prior two elements: ]prev2Inj = Injector (\x i@(prev1May, prev2May) -> (i, (Just x, prev1May))) (Nothing, Nothing)or random values, etc.MapWithTthe first argument is a generate function, the second argument is the initial state.MapWithinject  if the item is at the limit:%from the left: if it's the first item%from the right: if it's the last itemelse inject False.MapWithinject the item index:6from the left: the first item is 0, the second 1, etc.;from the right: the last item is 0, the penultimate 1, etc.MapWith"Inject each given element in turn:Lfrom the left: the first element will be injected for the first item in the .Lfrom the right: the first element will be injected for the last item in the .aAs a result of laziness, it is not always an error if there are not enough elements, for example:6drop 1 $ mapWith ((\_ i -> i) <-^ eltFrom [8,2]) "abc"[2,8] MapWitha safe version of  . Injects  each given element in turn, or  after they've been exhausted. MapWitha safe version of R. Injects each given element in turn, or the default after they've been exhausted. MapWithinject  the adjacent item:;from the left: the previous item, except for the first itemgfrom the right: the next item, except for the last item. (The "previous from the right" is the "next".)inject : if there is no adjacent item (i.e. for the first / last). MapWithmaps an  over a  type t , turning a t a into a t b! and preserving the structure of t.Parameters (as defined in the 0) are passed to a map function (embedded in the &), in addition to the elements of the . MapWithlike , but with an .MapWithlike  (which is like ' but ignores the results), but with an .MapWithlike  , but with an MapWith, from the left.MapWith, from the right.MapWith , from the left.MapWith , from the right.MapWith Maps over a c, with additional parameters indicating whether an item is the first or last (or both) in the list.‚let f x isFirst isLast = star isFirst ++ x ++ star isLast; star b = if b then "*" else "" in withFirstLast f ["foo", "bar", "baz"]["*foo", "bar", "baz*"]MapWith !andFirstLast = withFirstLast (,,)MapWith Maps over a G, with additional parameters indicating the previous and next elements.7The second (or third) parameter to the map function is : when called for the first (or last) item, otherwise it's  the previous (or next) item.—let f x prvMay nxtMay = maybe "*" (cmp x) prvMay ++ x ++ maybe "*" (cmp x) nxtMay; cmp x y = show $ compare x y in withPrevNext f ["foo", "bar", "baz"]["*fooGT","LTbarLT","GTbaz*"]MapWith andPrevNext = withPrevNext (,,)MapWith6The elements to inject. There must be enough elements.    11!      !"!#$%&%'(&MapWith-0.1.0.0-3W6qH9oxaZcFUPGI6YKn7eMapWith Injectable^-><-^ InjectedFnInjectorisLimeltIxeltFrom eltFromMay eltFromDefadjEltmapWithmapWithM mapWithM_ foldMapWithisFirstisLastprevEltnextElt withFirstLast andFirstLast withPrevNext andPrevNext$fInjectableInjectedFn$fInjectable->baseData.Traversable Traversableghc-prim GHC.TypesTrue GHC.MaybeJustNothingmapM Data.FoldablemapM_foldMap