Comments (13)
Following some links, I found this comment:
Overloads, whenever possible, should always have a final overload that covers all of the cases in a more general way
-- microsoft/TypeScript#40413 (comment)
This makes it sound like perhaps the problematic overload can be rephrased for TypeScript to "fall back" to the "map
on Future
" case when it can't resolve the overload. I will investigate this option.
from fluture.
it brought this repo to mind as it's the HKT implementation that has made the most sense to me to date, but I'm not convinced it's any simpler than his solution. I learned a ton today! Many thanks to you both ๐
That traverses down the type and replaces _<0>
, _<1>
, etc., which thus doesn't support conditional types, which is normally half of my use case ๐ . Creating the HKTs with it is a bit simpler, however, so if you're just using HKTs for a Functor-esque purpose like this, it's probably better.
from fluture.
I should note that chain
can infer types just fine (i.e. same behavior as fluture 11.x), so this is specific to map
from fluture.
Hi @EricCrosson. Thanks for the report. I think it's because the second argument to map
is overloaded with support for the ConcurrentFuture
type besides the Future
type:
Lines 138 to 143 in 2f12660
TypeScript cannot infer types from overloaded functions (microsoft/TypeScript#32418 (comment)).
In Fluture v11, this overload was incorrectly specified at the first function argument:
Lines 271 to 277 in 00959c7
This means that TypeScript always resolves to the first overload that matches the input function (as opposed to the type of Functor), which is the version of map
used on Future
(see #400). So in v11, it worked for Future instances, but not for ConcurrentFuture instances. This was fixed over several iterations: first #401 and then #403.
I believe this is a case where fixing one issue introduces the other, and vice-versa. I've also had trouble with TypeScript's inference from overloaded functions when I was trying to do #438, leading me to have abandoned it for now. I would love for this problem to be solved somehow, but no luck so far. We can leave this issue open for visibility.
from fluture.
Oh, and the reason my preference is to leave it at the current solution, and not go back to the v11 way (essentially dropping support for map
on ConcurrentFuture
), is because the problem caused by the current approach is easier to solve in userland, via a type annotation. In other words, it seems like the lesser of two evils.
from fluture.
@EricCrosson As a work-around, you could create a Future-specialized map
function, eg:
import * as F from 'fluture'
export function map<RA, RB>(mapper: (value: RA) => RB):
<L>(source: F.FutureInstance<L, RA>) => F.FutureInstance<L, RB> {
return F.map (mapper)
}
///////////////////////////////////////////////
F.resolve(5)
.pipe(map(value => value.toString()))
from fluture.
@Avaq, thank you for the quick response and suggested workaround!
I appreciate the historical context you have provided. There's a lot to read and think about, so I may take some time to digest all of this.
from fluture.
Another option I have been thinking about is to create more separation between the Future
and ConcurrentFuture
types, so that both can support their entire feature-set "out of the box", but I like the sound of the final overload much more
from fluture.
@EricCrosson I've started working on this, although have been unsuccessful in finding a solution. See #457.
from fluture.
I also asked for help with this issue on TypeScript's Discord: https://discord.com/channels/508357248330760243/740274647899308052/796759112607203399
from fluture.
Awesome, I didn't know there was a TypeScript discord! I'll check out your post there and the PR to see if I can help
from fluture.
Someone on the Discord channel found a solution. I committed it to #457. Perhaps you could install npm i fluture-js/fluture#avaq/map-ts
and test if this has solved your issue? Note that this may not work with ts-node
due to its reliance on CJS, but you can test with tsc
.
from fluture.
Sure! I'm reading through the discord conversation now -- coolest back-and-forth I've seen in a while ๐
I've never fully grokked the other [HKT] encodings I've seen
it brought this repo to mind as it's the HKT implementation that has made the most sense to me to date, but I'm not convinced it's any simpler than his solution. I learned a ton today! Many thanks to you both ๐
Testing fluture-js/fluture#avaq/map-ts
locally
Yes sir! The example in my initial post compiles without a hitch, and my editor correctly infers that value
is of type number
. This ticket can be closed. Dynamite! ๐งจ
Consider me officially excited to upgrade my projects from fluture 11 to fluture ๐
from fluture.
Related Issues (20)
- Error in readme HOT 4
- Can`t realize ap composition HOT 6
- Is it proven that Fluture Future is lawful? HOT 4
- Access computation value as return value HOT 3
- Why does encaseP / attemptP accepts only one parameter? HOT 4
- Event Streams handling HOT 5
- Any future for Fluture on React Native? HOT 4
- chainRej example doesn't include all code needed to replicate
- Consider preserving the specific Error sub-type when converting to Promise HOT 5
- Why not thenables? HOT 3
- Example Sanctuary integration code throws an error
- Investigate option for alternative debug api
- Make typings for algebras more strict
- It seams like `Hook (Future e a) b` is equivalent to `ContT a (Future e) b` HOT 1
- Add Future.assume?
- Async Iterators HOT 4
- Using Fluture with Jest HOT 1
- TypeScript error using map HOT 4
- Use result of Future
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluture.