Skip to content

Instantly share code, notes, and snippets.

@kitasuna

kitasuna/00.js

Last active Nov 5, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.