Questions tagged [sanctuary]

Sanctuary is a JavaScript functional programming library inspired by Haskell and PureScript.

Sanctuary is a JavaScript functional programming library inspired by Haskell and PureScript. It's stricter than Ramda, and provides a similar suite of functions.

Sanctuary promotes programs composed of simple, pure functions. Such programs are easier to comprehend, test, and maintain – they are also a pleasure to write.

Sanctuary provides two data types, Maybe and Either, both of which are compatible with Fantasy Land. Thanks to these data types even Sanctuary functions which may fail, such as head, are composable.

Sanctuary makes it possible to write safe code without null checks. In JavaScript it's trivial to introduce a possible run-time type error:

words[0].toUpperCase()

If words is [] we'll get a familiar error at run-time:

TypeError: Cannot read property 'toUpperCase' of undefined

Sanctuary gives us a fighting chance of avoiding such errors. We might write:

S.map(S.toUpper, S.head(words))

Sanctuary is designed to work in Node.js and in ES5-compatible browsers.

33 questions
0
votes
2 answers

Sanctuary Js and Defining a Contravariant Functor

I am trying this from scratch learning about Contravariants and deeper knowledge of Sanctuary. The code "works" but again I don't have the types exactly right. Here is the Contravariant const {contramap: contramapFl, extract } =…
akaphenom
  • 6,728
  • 10
  • 59
  • 109
0
votes
1 answer

What value should I pass to Sanctuary.either()?

I am trying to run the following example. It uses sanctuary.js. const {create, env} = require('sanctuary'); const S = create({checkTypes: false, env: env}); const test = require('tape'); class Person { constructor(name){ this.name =…
gburnett
  • 755
  • 8
  • 18
0
votes
1 answer

Type Values and "Accessible Pseudotype" in Sanctuary.js (Fantasy Land)

I am working through the documentation on Sanctuary.js. I've been working on learning Haskell also, and struggled a bit with FP concepts. I understand that a type value is an object that has (a) a constructor (the type representative), (b) a type…
webstackdev
  • 850
  • 15
  • 23
1 2
3