fvilante / NextRobot

The next robot framework
0 stars 0 forks source link

Provide Documentation #14

Open fvilante opened 4 years ago

fvilante commented 4 years ago

Any promise inside a lazy-pure type like in Result<E,Promise<A>> is impure.

Instead of Promise use Future everywhere.

fvilante commented 4 years ago

Good: fold and bimap are preatty intercallable


  const a0 = f1.fold(
        err => `Finished: Throw this error --> ${err}`,
        value => `Finished: Successful, value --> ${ value }`,
    )

  const a1 = f1.bimap(
        err => `Finished: Throw this error --> ${err}`,
        value => `Finished: Successful, value --> ${ value }`,
    )
fvilante commented 4 years ago

Difference folde and match:

  fold: <R>(errorFn: (_: E) => R, valueFn: (_:A) => R) => Result<void,R>
  match: <R>(errorFn: (_: E) => R, valueFn: (_:A) => R) => R
fvilante commented 4 years ago

Important to note that this structure is Recursive Monad<E,Monad<E,A>> and the normaly in aflatten` operation the first E may abort the perception of the second.

17

fvilante commented 4 years ago

State clearly in docs: DO NOT USE TYPE COERSION, unless you know exactly what you are doing. Type coersion is rarelly necessary. If you do it wrong you compromise type safety of all code downstream. Show cases of Either where some type annotation (not coersion!) is necessary.

fvilante commented 4 years ago

Docs should alert that is not expected to use functions like the update (bellow) to cause side-effect. They can monitor the number that are flowing but avoid to cause side-effect

function f also must be pure.

/** Models safe natural numbers. ex: 1, 2, 3...*/
type Natural = {
    readonly kind: 'Natural'
    readonly run: () => Result<string,number>
    readonly update: (f: (n: number) => number) => Natural
}
fvilante commented 4 years ago

unsafeRun and Run convention on Algebraic types

unsafe is used in when you break the 'lazyness' contract, if you do not break the contract applying that combinator the convention is to use just run without 'unsafe' term.