Skip to content

Instantly share code, notes, and snippets.

@ThomasCrevoisier
Created March 2, 2015 22:32
Show Gist options
  • Select an option

  • Save ThomasCrevoisier/af1a47fc2628a262d600 to your computer and use it in GitHub Desktop.

Select an option

Save ThomasCrevoisier/af1a47fc2628a262d600 to your computer and use it in GitHub Desktop.
Foreign Import
{- Non-working version -}
foreign import mapHRecLabel
"function mapHRecLabel(f, rec) {\
\ var mapped = {};\
\ for (var k in rec) {\
\ if (rec.hasOwnProperty(k)) {\
\ mapped[k] = f(k, rec[k]);\
\ }\
\ }\
\ return mapped;\
\}" :: forall a b. Fn2 (String -> a -> b) (HRec a) (HRec b)
{- Working version -}
foreign import mapHRecLabel
"function mapHRecLabel(f, rec) {\
\ var mapped = {};\
\ for (var k in rec) {\
\ if (rec.hasOwnProperty(k)) {\
\ mapped[k] = f(k)(rec[k]);\
\ }\
\ }\
\ return mapped;\
\}" :: forall a b. Fn2 (String -> a -> b) (HRec a) (HRec b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment