Skip to content

UnrelatedString/purescript-lua-foreign-object

 
 

Repository files navigation

purescript-lua-foreign-object

CI Latest Version Tag Pursuit

Functions for working with homogeneous Lua tables from PureScript. Similar to using Map String a but simply reusing Lua tables, with the same API as foreign-object for the default JavaScript backend.

Installation

spago install foreign-object

Example

example = do
  let
    -- make an empty Object
    empty = FO.empty

    -- insert to an empty Object
    inserted = FO.insert "a" 1 empty

    -- or: use the singleton function
    -- singleton FO.singleton "a" 1

  -- lookup values for existing in the Object as a result of Maybe
  let lookup = FO.lookup "a" inserted
  Assert.assertEqual { actual: lookup, expected: Just 1 }

  -- delete a value from an Object
  let deleted = FO.delete "a" inserted
  Assert.assertEqual { actual: deleted, expected: FO.empty }

  let
    -- convert homogeneous records to Object
    converted = FO.fromHomogeneous { a: 1, b: 2, c: 3}
    -- check that the converted is equal to a regularly built Object
    built
      = FO.empty
      # FO.insert "a" 1
      # FO.insert "b" 2
      # FO.insert "c" 3

  Assert.assertEqual { actual: converted, expected: built }

See the tests for more examples.

Documentation

Module documentation is published on Pursuit.

About

Functions for working with homogeneous Lua tables, with an API compatible with the JavaScript implementation of `foreign-object`

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • PureScript 89.2%
  • Lua 8.4%
  • Dhall 2.4%