Mostly Adequate with fp-ts
1.0.0
1.0.0
  • Welcome
  • Chapter 01: What Ever Are We Doing?
  • Chapter 04: Currying
  • Chapter 05: Coding by Composing
  • Chapter 06: Example Application
  • Chapter 08: Tupperware
  • Chapter 09: Monadic Onions
  • Chapter 10: Applicative Functors
Powered by GitBook
On this page

Was this helpful?

Chapter 10: Applicative Functors

Apply

Maybe.of(add).ap(Maybe.of(2)).ap(Maybe.of(3));
// Maybe(5)

// Http.get :: String -> Task Error HTML

const renderPage = curry((destinations, events) => { /* render page */ });

Task.of(renderPage).ap(Http.get('/destinations')).ap(Http.get('/events'));
// Task("<div>some page with dest and events</div>")
import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/function";

declare const Http: {
  get: (url: string) => TE.TaskEither<Error, string>
}

const renderPage = (destinations: string) => (events: string) => {
  return `<div>${destinations}${events}<div>`;
};

pipe(
  TE.right(renderPage),
  TE.ap(Http.get("/destinations")),
  TE.ap(Http.get("/events"))
);
PreviousChapter 09: Monadic Onions

Last updated 4 years ago

Was this helpful?