Created
January 25, 2019 18:46
-
-
Save adamczykm/fa4b169d1116d024f424cc13d3ec8eac to your computer and use it in GitHub Desktop.
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
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