I am trying to extend my function toTuple so that it takes [(d1, Just x), (d2, Just y), (d3, Just z)] and produces [(d1, d2, y), (d2, d3, z)]
import qualified Data.Function.Step.Discrete.Open as SF import qualified Data.Map as Map newtype DayMap a = DayMap (SF.SF Day (Maybe a)) deriving stock (Show, Functor) toTuple :: Map.Map Day (Maybe a) -> [(Day, Maybe Integer)] toTuple a = produceList where produceList = Map.toList (getDM td3) getDM :: DayMap a -> Map.Map Day (Maybe a) getDM (DayMap sf@(SF.SF m hi)) = m td3 :: DayMap Integer td3 = DayMap.insert (Just $ fromGregorian 2010 01 01) (Just $ fromGregorian 2012 01 01) 22 DayMap.empty It currently produces this:
> toTuple (getDM td3) [(2010-01-01,Nothing),(2012-01-02,Just 22)] I.e. the value Just 22 is relevant between 2010-01-01 and 2012-01-02 and is empty before that.
So i want to end up with [(2010-01-01, 2012-01-02, (Just 22))] in this case.
I'm not clear on how to extend my toTuple function. Any tips would be appreciated.
Just xhere?[(2010-01-01, 2012-01-02, (Just 22))]zipWith (\(x,_) (y,z) -> (x,y,z)) (tail data) data.(tail data) datapart though. Could you elaborate?tailreturns the list but without the first element, so that means we zip each item with the next one. So the first item(x,_)with the second(y,z); and the second(x,_)with the third(y,z); and so on.