Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #2

Open
davidchase opened this issue Oct 11, 2016 · 1 comment
Open

Feedback #2

davidchase opened this issue Oct 11, 2016 · 1 comment

Comments

@davidchase
Copy link
Contributor

davidchase commented Oct 11, 2016

Really having a good time with this soon to be "real" project 😂 made a wrapper around fetch https://github.com/davidchase/yet-another-fetch which somewhat works the way I want but wanted to get some thoughts..

currently with yet:

import {runTask, task} from '@briancavalier/yet'

const listTask = task(resolve => resolve([1,2,3]))

const [kill, futureValue] = runTask(listTask)

futureValue.map(console.log) //=> 1, 2, 3

i think the expected should be the [1, 2, 3] list?

I first noticed it with yet-another-fetch because futureValue.map(console.log) was logging a value instead of an Either

From what i gather the culprit is F.map and it does the check for if x has map and then uses it
https://github.com/briancavalier/yet/blob/master/src/FutureValue.js#L52
https://github.com/briancavalier/yet/blob/master/src/FutureValue.js#L67

my current workaround is just to do f(future.value) and this.f(value) respectively so maybe we don't need to use F.map in that case... thoughts?

really digging the ability to kill off a task especially with fetch because i can prevent the request from happening altogether 👍

@briancavalier
Copy link
Owner

Thanks for the feedback @davidchase :)

futureValue.map(console.log) //=> 1, 2, 3
...
i think the expected should be the [1, 2, 3] list?

This is intentional. The idea is based on Conal's type class morphism paper. We talked about it a bit over in this creed issue, and I decided to try it out. The idea is:

fmap f (FutureValue a) = FutureValue (fmap f a)

To put it into words: An fmapped FutureValue of a is a FutureValue of an fmapped a. In the example you gave, a is type Array Int. So:

fmap f (FutureValue (Array Int)) = FutureValue (fmap f (Array Int))

Which applies f to each element of the array. Make sense?

I'm planning to add other functions that will allow access to the value as a whole (e.g. you could console.log the whole array rather than one item at a time, if you wanted), but I'm kinda digging this type class morphism approach for certain type classes, like Functor in the case of map, and probably at least Applicative and Monoid as well.

really digging the ability to kill off a task especially with fetch because i can prevent the request from happening altogether

Yay! Glad to hear that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants