fvilante / NextRobot

The next robot framework
0 stars 0 forks source link

Grasp the Monad-like structure #44

Open fvilante opened 4 years ago

fvilante commented 4 years ago

There's I way, to write a source into a file that seems so structured, reproductive and scalable. I'll monitor it here, to see if it can become something apt to the style guide

43

fvilante commented 4 years ago

It's necessary to make this esier to do a type query on implementations. Bellow (type A line) is an example of what we want to improve.

const fromMaybe: Future_['fromMaybe'] = ma => {
    type A = Parameters<Parameters<ReturnType<typeof ma>['map']>[0]>[0] // <-- Should be easier
    return Future_.fromResult<void,A>( () => Result.fromMaybe(ma()))
}

14

fvilante commented 4 years ago

One idea is to define among the structure elements a element with allow to pick the type parameter gieven an instance of the Algebraic type. For example:

type __InspectorOfFuture<T extends Future<any,any>> = {
     readonly E: ...
     readonly A: ...
}
fvilante commented 4 years ago

>99% type inference

I noticed that most of the time the above kind of patter (expressed as type A) can be avoided with some code refactoring. I have a strong feeling that is it possible do have automatic inference in pratically all circunstances.