Last active
November 5, 2018 22:15
-
-
Save kitasuna/f552cef8fa37a950897c8632d4738cb9 to your computer and use it in GitHub Desktop.
Defining Custom Types in Sanctuary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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