module Music.Theory.Traversable where
import Data.List
adopt_shape :: Traversable t => (a -> b -> c) -> [b] -> t a -> ([b],t c)
adopt_shape :: forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> c) -> [b] -> t a -> ([b], t c)
adopt_shape a -> b -> c
jn [b]
l =
let f :: [b] -> a -> ([b], c)
f (b
i:[b]
j) a
k = ([b]
j,a -> b -> c
jn a
k b
i)
f [] a
_ = forall a. HasCallStack => [Char] -> a
error [Char]
"adopt_shape: rhs ends"
in forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL [b] -> a -> ([b], c)
f [b]
l
adopt_shape_2 :: (Traversable t,Traversable u) => (a -> b -> c) -> [b] -> t (u a) -> ([b],t (u c))
adopt_shape_2 :: forall (t :: * -> *) (u :: * -> *) a b c.
(Traversable t, Traversable u) =>
(a -> b -> c) -> [b] -> t (u a) -> ([b], t (u c))
adopt_shape_2 a -> b -> c
jn = forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL (forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> c) -> [b] -> t a -> ([b], t c)
adopt_shape a -> b -> c
jn)
adopt_shape_2_zip_stream :: (Traversable t, Traversable u) => [c] -> t (u a) -> t (u (c, a))
adopt_shape_2_zip_stream :: forall (t :: * -> *) (u :: * -> *) c a.
(Traversable t, Traversable u) =>
[c] -> t (u a) -> t (u (c, a))
adopt_shape_2_zip_stream [c]
s t (u a)
l = forall a b. (a, b) -> b
snd (forall (t :: * -> *) (u :: * -> *) a b c.
(Traversable t, Traversable u) =>
(a -> b -> c) -> [b] -> t (u a) -> ([b], t (u c))
adopt_shape_2 (forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)) [c]
s t (u a)
l)
list_number_2 :: [[x]] -> [[(Int,x)]]
list_number_2 :: forall x. [[x]] -> [[(Int, x)]]
list_number_2 = forall (t :: * -> *) (u :: * -> *) c a.
(Traversable t, Traversable u) =>
[c] -> t (u a) -> t (u (c, a))
adopt_shape_2_zip_stream [Int
1..]
adopt_shape_m :: Traversable t => (a -> b-> c) -> [b] -> t (Maybe a) -> ([b],t (Maybe c))
adopt_shape_m :: forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> c) -> [b] -> t (Maybe a) -> ([b], t (Maybe c))
adopt_shape_m a -> b -> c
jn [b]
l =
let f :: [b] -> Maybe a -> ([b], Maybe c)
f (b
i:[b]
j) Maybe a
k = case Maybe a
k of
Maybe a
Nothing -> (b
iforall a. a -> [a] -> [a]
:[b]
j,forall a. Maybe a
Nothing)
Just a
k' -> ([b]
j,forall a. a -> Maybe a
Just (a -> b -> c
jn a
k' b
i))
f [] Maybe a
_ = forall a. HasCallStack => [Char] -> a
error [Char]
"adopt_shape_m: rhs ends"
in forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL [b] -> Maybe a -> ([b], Maybe c)
f [b]
l