Skip to content

Instantly share code, notes, and snippets.

@adamczykm
Created January 25, 2019 18:46
Show Gist options
  • Save adamczykm/fa4b169d1116d024f424cc13d3ec8eac to your computer and use it in GitHub Desktop.
Save adamczykm/fa4b169d1116d024f424cc13d3ec8eac to your computer and use it in GitHub Desktop.
module Utils where
import Data.Array (snoc)
import Data.FormURLEncoded (FormURLEncoded(..))
import Data.Function (($))
import Data.Maybe (Maybe(..))
import Data.Monoid (mempty)
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
import Data.Tuple (Tuple(..))
import Heterogeneous.Folding (class FoldingWithIndex, class HFoldlWithIndex, hfoldlWithIndex)
data Record2UriParams = Record2UriParams
foreign import encodeURIComponent :: String -> String
instance record2UriParams ::
IsSymbol sym =>
FoldingWithIndex Record2UriParams (SProxy sym) FormURLEncoded String FormURLEncoded where
foldingWithIndex Record2UriParams prop (FormURLEncoded acc) a =
FormURLEncoded $ snoc acc (Tuple (reflectSymbol prop) (Just $ encodeURIComponent a))
encodeAsUriParams :: forall r. HFoldlWithIndex Record2UriParams FormURLEncoded r FormURLEncoded => r -> FormURLEncoded
encodeAsUriParams r = hfoldlWithIndex Record2UriParams (mempty :: FormURLEncoded) r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment