Closed lsby closed 4 years ago
Hello, @lsby, and welcome to the Sanctuary community. :wave:
I noticed that in "sanctuary-def", I can use the function "def" returned by "$ .create" to define a new function.
That's the way to do it. :)
So how do I define my own functions in a "sanctuary"?
Sanctuary itself does not provide this functionality; you need to depend on sanctuary-def. If you are using Sanctuary in your project, depending on sanctuary-def directly will not affect your bundle size as it is already a transitive dependency.
Here is a minimal example:
const $ = require ('sanctuary-def');
const def = $.create ({checkTypes: true, env: $.env});
// greet :: String -> String
const greet =
def ('greet')
({})
([$.String, $.String])
(name => `Hello, ${name}!`);
@davidchambers , I get it now, thanks!
Hi, I really like this project and it's very exciting. Although it lacks some introductory material.
I checked the documentation for "sanctuary" and "sanctuary-def". I noticed that in "sanctuary-def", I can use the function "def" returned by "$ .create" to define a new function.
But in "sanctuary", there is an example of using a document:
Where "S" is not the "def" in "sanctuary-def". "S.def" also does not exist.
I checked the "sanctuary" source code.
The "def" obtained did not appear to be exposed.
So how do I define my own functions in a "sanctuary"?