Skip to content

Implementation of tuples as a flat heterogeneous array, for FFI

License

Notifications You must be signed in to change notification settings

citizennet/purescript-tuples-native

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purescript-tuples-native

This library defines tuple data types that are represented under-the-hood as heterogeneous arrays to JavaScript - useful for foreign interfaces. A set of xt functions are exposed to translate these native Tuples into Purescript pairs or Nested tuples. So for example:

-- Main.purs
import Data.Tuple.Native (T2, xt)
import Data.Tuple (Tuple)

foreign import lenTupleImpl :: String -> T2 String Int

lenTuple :: String -> Tuple String Int
lenTuple s = xt $ lenTupleImpl s

Could let you wrap this Javascript function

"use strict";
function lenTuple (string) {
    return [string, string.length]
}
exports.lenTupleImpl = lenTuple

You can also extract indidual elements directly from the Native tuple using prj.

import Data.Tuple.Native (T3, t3, prj)
import Data.TypeLevel.Num.Reps (d0, d1, d2)

xs :: T3 String Int Boolean
xs = t3 "foo" 13 false

prj d0 xs == "foo" -- true
prj d1 xs == 13 -- true
prj d2 xs == false -- true

About

Implementation of tuples as a flat heterogeneous array, for FFI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PureScript 76.8%
  • Dhall 19.4%
  • JavaScript 3.8%