Skip to content

Instantly share code, notes, and snippets.

@chexxor
Created April 20, 2018 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chexxor/38c8c98cf10e8694c4bed02e72b3169e to your computer and use it in GitHub Desktop.
Save chexxor/38c8c98cf10e8694c4bed02e72b3169e to your computer and use it in GitHub Desktop.
WithPipeline
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