Given a list :: [(Foo, Bar)], I’d like to perform a scanl1 on the Bars, but preserve their Foo “tags”.
I.e. I’d like a function with the type :: [(a, b)] -> ([b] -> [c]) -> [(a, c)], so that I can pass a curried scanl1 as the second argument.
I can write it recursively, but it feels like there’s a way to compose higher-order functions to do this.
Is this already possible with standard functions?
Instead of writing an unsatisfying higher order function, you could lift your combining function to thread the
Footags through so you can still usescanl1, which is what you mean.Now you can use
scanl1; take your originalqux :: Bar -> Bar -> Barand makekeeptagsis simple andscanQuxis crystal clear.For example, if
then you get
as you had hoped.