Questions tagged [sanctuary]
Sanctuary is a JavaScript functional programming library inspired by Haskell and PureScript.
33
questions
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 ...
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 ...
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 ...
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 ...
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 ...
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 =...
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),
...
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 ...
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 ...
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(...
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 ...
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! ...
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 ...
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 ...
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 ...
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 ...
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');
...
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 ...
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 ...
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 ...
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, ...
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 {...
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 ...
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 ...
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 ...
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 ...
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)
...
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 ...
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 ...
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 ...
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-...
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]
...
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 ...