Created
January 25, 2019 18:34
-
-
Save adamczykm/86c489ba3070c092afaeca3a2d76924c 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.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 String { | r } FormURLEncoded => | |
{ | r } -> | |
FormURLEncoded | |
encodeAsUriParams r = hfoldlWithIndex Record2UriParams "" r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment