Skip to content

Instantly share code, notes, and snippets.

@kitasuna
Last active November 5, 2018 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitasuna/f552cef8fa37a950897c8632d4738cb9 to your computer and use it in GitHub Desktop.
Save kitasuna/f552cef8fa37a950897c8632d4738cb9 to your computer and use it in GitHub Desktop.
Defining Custom Types in Sanctuary
const S = require('sanctuary')
const $ = require('sanctuary-def')
const x = 42
const s = "butter"
// this will work
const oops = x + s
// this will blow up
const result = S.add(x)(s)
const someUser = {
  id: 3,
  name: "Eric",
  email: "me@dokidoki.whatever"
}
const someProduct = {
  id: 123,
  name: "Exciting consumer item!"
}
const updateProductName =
  (product, newName) => {
    return Object.assign(
      {},
      { ...product },
      { name: newName }
    )
}
// pass in user instead of product...
// ... aaaand it works. Kind of.
const newProduct = updateProductName(
  someUser,
  "Suggestive Refrigerator Magnet"
)
const $ = require('sanctuary-def')
const { create, env } = require('sanctuary')
const FirstType = $.NullaryType
('dokidoki-types/FirstType')
('http://dokidokidriven.com/types/FirstType')
((x) => x === "dokidoki")
const S = create({checkTypes: true, env: env.concat ([FirstType])})
const result = S.add(42)("dokidoki")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment