Questions tagged [sanctuary]

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

Filter by
Sorted by
Tagged with
1 vote
0 answers
34 views

Which JavaScript lib has feature similar to Haskell's do-notation or Scala's for-comprehension?

I am exploring a few JavaScript libraries for functional programming such as Ramda, Sanctuary, etc.,. I've also checked their pipe and compose functions for chaining and composition. But they can't do ...
Pyi Soe's user avatar
  • 111
0 votes
1 answer
41 views

fantasy-land confusion on ap method signature

In fantasy-land spec, the signature for ap method is defined as fantasy-land/ap :: Apply f => f a ~> f (a -> b) -> f b This translates as: The container f with value a has a method ap ...
rsmoorthy's user avatar
  • 2,284
1 vote
0 answers
294 views

Functional programming: handling null results with sanctuary.js and Monad

I am new to the world of functional programming and am trying to work through a few points of confusion to me with Sanctuary.js. Here is the scenario, I would like to use a pipe to handle reading ...
user1790300's user avatar
  • 2,043
1 vote
1 answer
43 views

Wrong answer from S.min when strings used

S.min ('1') ('02') =>'02' Why is this even possible? (yes type coercion... but this is Sanctuary) Can Sanctuary be configured so that Nothing is returned when Strings are used? Is there an elegant ...
Niel Ryan's user avatar
  • 1,123
1 vote
1 answer
287 views

Data modelling challenges in sanctuary.js

I am building an app based on domain-driven design using functional programming in javascript. I've settled on the sanctuary.js ecosystem as my tool of choice, but I'm facing some challenges in ...
ceblay's user avatar
  • 23
1 vote
1 answer
125 views

Operating on two Eithers

Suppose that you have the following code: import R from "ramda"; import S from "sanctuary"; import { Left, Right } from "sanctuary-either"; const add = R.curry((p1, p2) => p1 + p2); const addOne =...
antoniom's user avatar
  • 3,153
1 vote
0 answers
196 views

Sanctuary `Maybe` refers to a value, but being used as type here

I have a function like this export const createMemberId: (x: any) => Maybe<MemberId> = (x: any) => { try { return Just({ memberId: mongoose.Types.ObjectId(x), ...
mohsen saremi's user avatar
1 vote
1 answer
282 views

A more idiomatic way to write sanctuary pipe

I wrote a code snippet that extracts the source object keys (which are supposed to be unknown so I've added a non-existing key baz to be extracted. Every element in the array that I extract - I want ...
MaxG's user avatar
  • 1,079
0 votes
1 answer
274 views

execute Fluture task with Sancuary Either

I have a pipe like this const asyncFn = (x) => { return Future.tryP(() => Promise.resolve(x + ' str2')) }; const pipeResult = S.pipe([ x => S.Right(x + " str1"), // some validation ...
mohsen saremi's user avatar
1 vote
1 answer
357 views

Execute Fluture task in middle of Sanctuary pipe

I have a pipe like this: S.pipe([ getRequestFile, // not async S.chain(saveTemporary), // not async S.chain(copyImageToPublicPath), // async S.chain(...
mohsen saremi's user avatar
2 votes
1 answer
116 views

Sanctuary js execute 2 steps of pipe with condition

I have a S.pipe for upload and manipulate incoming request file S.pipe([ getRequestFile, S.chain(saveTemporary), S.chain(checkIfIsImage), S.chain(addWatermarkToImage), // only ...
mohsen saremi's user avatar
1 vote
0 answers
151 views

Know if value is defined as Nullable or NotNullable when resolving custom scalar type

I'm creating custom scalar types that override the built in Int and Float. I'd like to know whether the schema defines the value as nullable or not. I'd like to resolve an Int differently than Int! ...
Abdul Taleb's user avatar
1 vote
2 answers
374 views

Merge multiple objects with Sanctuary.js

I am trying to merge multiple objects with Sanctuary. With Ramda.js I would do something like this (see the REPL here): const R = require('ramda'); const initialEntry = { a: 0, b: 1 }; const entries ...
jackdbd's user avatar
  • 4,593
0 votes
2 answers
265 views

Multiple if's refactoring

I have this function, with two ifs where I want to find the user depending on which alphanumeric code I receive. How can I refactor this one with sanctuary-js? //const code = '0011223344'; const code ...
Ivan's user avatar
  • 2,463
0 votes
1 answer
66 views

Set property when value is Just

I would like to set the property of an object when the value is Just, and not to set the property when the value is Nothing. However, if the value is Nothing, the returned object become Nothing. let ...
Franz Wong's user avatar
  • 1,034
0 votes
1 answer
162 views

What does it actually mean Left and Right in sanctuary

> S.reduce(S.flip(S.K),[],S.Left([1,2])) [] > S.reduce(S.flip(S.K),[],S.Right([1,2])) [ 1, 2 ] I was trying to understand sanctuary and its working can anybody explain the above outcomes in ...
codefreaK's user avatar
  • 3,584
0 votes
1 answer
139 views

Mapping with sanctuary over fantasy-land IO [closed]

I have a small code sample that works as I expected it to when using ramda, but my attempt to port this to sanctuary has failed. const IO = require('fantasy-io'); const S = require('sanctuary'); ...
Daniel Chicot's user avatar
4 votes
2 answers
942 views

How do I collapse Maybe monads in sanctuary js

Here is a simple chained expression using modern javascript to find the value for a specific key located in a string containing a comma separated list of key-value pairs separated by =. This falls ...
joshperry's user avatar
  • 41.2k
1 vote
1 answer
86 views

Error with simply Maybe funtion

Background I am trying to help someone in StackOverflow with a question regarding Futures and Maybes and Eithers. My first approach is to have a simple function that takes in a Maybe and computes ...
Flame_Phoenix's user avatar
2 votes
1 answer
282 views

How to log properly in Sanctuary / Fluture?

Background I have a function, called logInfoAsync. Let's consider this function sends some information to a log server over the network. For the purposes of this question let's assume the function is ...
Flame_Phoenix's user avatar
1 vote
2 answers
271 views

How to stub Fluture?

Background I am trying to convert a code snippet from good old Promises into something using Flutures and Sanctuary: https://codesandbox.io/embed/q3z3p17rpj?codemirror=1 Problem Now, usually, ...
Flame_Phoenix's user avatar
0 votes
2 answers
376 views

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 {...
akaphenom's user avatar
  • 6,728
0 votes
1 answer
294 views

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 ...
gburnett's user avatar
  • 765
2 votes
1 answer
380 views

Sanctuary.Js Type Error with Identity Functor

I am playing around following Bartosz Milewski category theory lessons on youtube. He describes Const and Identity functors as the "base" functors can be derived from (probably a liberal paraphrasing ...
akaphenom's user avatar
  • 6,728
4 votes
4 answers
382 views

What's the cleanest fp way to get a property pointed by another property

Given an object that may be null and may have the following properties: { templateId: "template1", templates: { template1: "hello" } } How would you get the template in a ...
Tiago Coelho's user avatar
  • 5,023
2 votes
2 answers
500 views

Confusion in understanding Substitution / `ap` type signature and different implementations (functional programming)

I am a student of functional programming, sorry if my question sounds weird--I am trying to wrap my mind around the given type signatures for functions and how they are implemented. Looking at the ...
Babakness's user avatar
  • 2,954
6 votes
2 answers
674 views

Using `.of` Constructor on Sanctuary Maybe

I'm working through a tutorial on functional programming that shows the following code example using the sanctuary.js library: var S = require('sanctuary') var Maybe = S.Maybe S.add( Maybe.of(3) ...
webstackdev's user avatar
0 votes
1 answer
161 views

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 ...
webstackdev's user avatar
1 vote
1 answer
118 views

Can I make "over" via object propery with Sanctuary

Ramda was my first library of functional programming and now I compare Sanctuary with Ramda. Maybe some my questions are too stupid, but I did not find best way to learn Sanctuary. My question is ...
Roman Valihura's user avatar
1 vote
1 answer
302 views

How does Curry differs between Sanctuary and Ramda?

I am stuck with the curry examples in "Professor's Frisby..." when using Sanctuary instead of Ramda. I get error: "‘curry2’ expected at most three arguments but received five arguments." while with ...
aym's user avatar
  • 233
3 votes
1 answer
163 views

Picking fields from object with certain RecordType with Sanctuary

I have an object with options that corresponds to the following record type: const AwsRegionsEnum = $.EnumType( 'AWS/Regions', 'http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-...
Roman Valihura's user avatar
3 votes
2 answers
3k views

How should I map over Maybe List?

I came away from Professor Frisby's Mostly Adequate Guide to Functional Programming with what seems to be a misconception about Maybe. I believe: map(add1, Just [1, 2, 3]) // => Just [2, 3, 4] ...
Ziggy's user avatar
  • 21.9k
10 votes
1 answer
679 views

Custom equality semantics for Immutable.js data structures

I would like Sanctuary to provide Fantasy Land -compatible Map and Set types with value-based equality semantics. Ideally these values would be immutable, though this is not critical since Sanctuary ...
davidchambers's user avatar