No description
Find a file
2024-11-27 14:27:53 +05:30
nix Upgrade to purescript 0.15.4 2022-09-12 19:11:07 +02:00
src/Data/Tuple Fix warnings (except the one about non exported data constructors - https://github.com/purescript-contrib/purescript-uint/issues/13). Add Eq, Ord, and Show instances. 2024-11-27 14:27:53 +05:30
test Fix warnings (except the one about non exported data constructors - https://github.com/purescript-contrib/purescript-uint/issues/13). Add Eq, Ord, and Show instances. 2024-11-27 14:27:53 +05:30
.envrc Upgrade to purescript 0.14.2 2021-06-22 12:25:46 +02:00
.gitignore spago support 2020-04-29 14:40:35 -07:00
bower.json Upgrade to purescript 0.14.2 2021-06-22 12:25:46 +02:00
LICENSE spago support 2020-04-29 14:40:35 -07:00
package.json Upgrade to purescript 0.15.4 2022-09-12 19:11:07 +02:00
README.md Add xt functions to coerce to PureScript Tuples 2020-07-19 15:14:29 +01:00
shell.nix Upgrade to purescript 0.15.4 2022-09-12 19:11:07 +02:00
spago.lock Move to new spago 2024-11-27 13:43:43 +05:30
spago.yaml Move to new spago 2024-11-27 13:43:43 +05:30

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