Questions tagged [fantasyland]

a specification for algebraic data structures in JavaScript.

25 questions
9
votes
3 answers

Mapping over an array of Tasks in Javascript

So I've started looking at Ramda / Folktale. I'm having an issue trying to map over an array of Tasks that comes from a directory. I'm trying to parse file contents. var fs = require('fs'); var util = require('util'); var R = require('ramda'); var…
SpaceBeers
  • 13,617
  • 6
  • 47
  • 61
6
votes
1 answer

Ramda with FP Types

Recently I have decided to switch from lodash to ramda to play with functional way of composing my logic. I love it! After some extensive digging into FP I have found that's it's not only about handy pure/point free utilities (ramda), but more about…
6
votes
2 answers

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) ,Maybe.of(5) ) .map(n => n * n) I get the error…
5
votes
2 answers

Combining Maybe and IO monads for DOM read/write

I'm trying to cook up a simple example using IO and Maybe monads. The program reads a node from the DOM and writes some innerHTML to it. What I'm hung up on is the combination of IO and Maybe, e.g. IO (Maybe NodeList). How do I short circuit or…
Will M
  • 2,135
  • 4
  • 22
  • 32
4
votes
3 answers

Difference between Type Class and Algebraic data types

As I understand the Type Class is that it's not something concrete but just a construct for ad-hoc and parametric polymorphism. Eq and Semigroup are examples of type classes. On the other hand, there is Algebraic data type, which is a concrete…
PunGy
  • 43
  • 4
4
votes
1 answer

What does it mean for a value to "have a functor"?

I'm new to this, and I may be missing something important. I've read part one of Category Theory for Programmers, but the most abstract math I did in university was Group Theory so I'm having to read very slowly. I would ultimately like to…
Ziggy
  • 21,845
  • 28
  • 75
  • 104
3
votes
1 answer

By using functional programming javascript with folktale2, how to access results of previous tasks gracefully?

A task has a few steps, if each step's input is only from direct last step, it is easy. However, more often, some steps are depend on not only the direct last step. I can work out via several ways, but all end up with ugly nested code, I hope anyone…
Ron
  • 6,037
  • 4
  • 33
  • 52
3
votes
0 answers

Using Task monads and Reader monads in javascript (DynamoDB and Facebook API)

here we have are trying to make a lot of calls in a functional way with javascript, the problem is that we end up with Reader.of(Task.of(Reader.of(Task.of))), so we need to map(map(map(map))) the values that we need to operate. The computation…
Nico
  • 1,241
  • 1
  • 13
  • 29
2
votes
1 answer

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 on my part). My problem, having implemented…
akaphenom
  • 6,728
  • 10
  • 59
  • 109
2
votes
1 answer

Folktale / fantasyland Maybe not working as expected

Reading Frisbys guide to functional programming, currently on the chapter about Maybe. In the appendix the book suggests using either folktale or fantasyland. However in both libraries Maybe doesn't seem to be work as described in the book. const…
2
votes
2 answers

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 signature for ap…
2
votes
1 answer

Ramda Pass "Maybe" Error Message Through Chain Calls

Lets say I have bunch of functions returns Just or Nothing values and I want to chain them together like this; var a = M.Just("5").map(function(data){ return 1; }).chain(function(data){ /*Make some operation return Just or Nothing */ …
1
vote
1 answer

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 = add(1); const func1 = () => Right(2); const func2…
antoniom
  • 3,143
  • 1
  • 37
  • 53
1
vote
1 answer

What does fantasy-land/id do?

fantasy-land/id :: Category c => () -> c a a I don't really understand what this signature says? id is a method that takes zero parameters and returns something that is a Category and two other things. Is that correct? What's the point of this?
Alper
  • 3,424
  • 4
  • 39
  • 45
1
vote
1 answer

Why does the fantasy land spec require that chain must return a value of the same Chain?

chain method A value which has a Chain must provide a chain method. The chain method takes one argument: m.chain(f) f must be a function which returns a value If f is not a function, the behaviour of chain is unspecified. f must return a…
user6445533
1
2