Fp-ts: Injecting stateful behavior

Created on 1 Nov 2019  路  2Comments  路  Source: gcanti/fp-ts

馃摉 Documentation

One thing is not obvious to me. Is createFoo function pure? I suppose it is. But we can not replace readFromDOM with value, so it's not referential transparent I suppose. Should we use IO?

export const createFoo = (
  value: JSON,
  readFromDOM: (selector: string) => Option<Element>,
): Foo => {
  // We use value for reading from DOM.
};

Most helpful comment

readFromDOM: (selector: string) => Option<Element> should be readFromDOM: (selector: string) => IO<Option<Element>>, so createFoo should return IO<Foo>.

All 2 comments

readFromDOM: (selector: string) => Option<Element> should be readFromDOM: (selector: string) => IO<Option<Element>>, so createFoo should return IO<Foo>.

OK, this talk explains it. https://www.youtube.com/watch?v=cxs7oLGrxQ4

A function is not and can not be pure when the injected function is impure.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gcanti picture gcanti  路  3Comments

miguelferraro picture miguelferraro  路  3Comments

jollytoad picture jollytoad  路  4Comments

mohsensaremi picture mohsensaremi  路  3Comments

bioball picture bioball  路  4Comments