You may also want to read this later discussion: https://groups.google.com/forum/#!topic/elm-discuss/Ud7WzAhRsqE
> Am 31.10.2016 um 07:25 schrieb David Andrews <[email protected]>: > > I found a discussion from May that has many thoughts on this. > > https://groups.google.com/d/msg/elm-discuss/u-6aCwaJezo/fu-HMPy6CQAJ > > My actual use case is that I'm looking into implementing a 0.17-compatible > local storage library (which I'll post about in another thread), and would > love to be able to write > eventsForKey : String -> Sub (Maybe String) > eventsForKey key = > events > |> Sub.filterMap (\x -> if x.key == key then Just x.newValue else > Nothing) > > which is implemented in terms of > events : Sub (Maybe String) > > > because I think it's a cleaner API than > eventsForKey : String -> (Maybe String -> msg) -> msg -> Sub msg > eventsForKey makeMsg noOp = > events > |> Sub.map (\x -> if x.key == key then makeMsg key.newValue else noOp) > > >> On Monday, October 31, 2016 at 1:31:08 AM UTC-4, David Andrews wrote: >> Right now, the Platform.Sub library has a map function which allows for >> transforming subscriptions. However, the initial and modified subscriptions >> will always produce the same number of messages. Are there plans to add >> filterMap and/or concatMap methods to Platform.Sub so that the number of >> messages can be modified? >> >> A simple use case (not that you would actually do this) would be >> Time.every Time.second identity >> |> Sub.filterMap (\x -> if floor x % 2 == 0 then Just x else Nothing) >> to implement >> Time.every (2 * Time.second) >> > > -- > You received this message because you are subscribed to the Google Groups > "Elm Discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
