Created
April 20, 2018 18:19
-
-
Save chexxor/38c8c98cf10e8694c4bed02e72b3169e to your computer and use it in GitHub Desktop.
WithPipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype WithPipeline a = WithPipeline (NEL.NonEmptyList (a -> a)) a | |
-- or -- | |
newtype WithPipeline a = WithPipeline (a -> a)) a | |
instance profunctorWithPipeline :: Profunctor (WithPipeline a) where | |
dimap :: forall a b c d. (a -> b) -> (c -> d) -> p b c -> p a d | |
dimap a2b c2d (WithPipeline f a) = WithPipeline (a2b >>> f >>> c2d) a | |
instance contraWithPipeline :: Contravariant (WithPipeline a) where | |
cmap :: forall a b. (b -> a) -> f a -> f b | |
cmap f' (WithPipeline f a) = WithPipeline (f <<< f') a | |
runPipeline :: WithPipeline a -> a | |
runPipeline (WithPipeline fs a) = flap fs a | |
-- ^ if first encoding of WithPipeline | |
type URLString = WithPipeline String | |
mkURLString :: String -> URLString | |
mkURLString = WithPipeline (NEL.singleton encodeURI) | |
unURLString :: URLString -> String | |
unURLString = runPipeline | |
-- in your app | |
href' :: forall eff. Location -> Eff (dom :: DOM | eff) URLString | |
href' loc = mkURLString <$> href loc | |
showURLParamInGUI :: URLString -> String | |
showURLParamInGUI = unURLString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment