January 2019
Beginner
210 pages
4h 47m
English
An Applicative is a Functor that implements a method named of. However, an Applicative is not just a Functor type; it is also an Apply type. For a type to be an implementation of Apply, it must implement a method named ap that takes a Functor that wraps a function as an argument.
The following code snippet implements an Applicative and, as a result, it has an of, a map, and an ap method:
class Container<T> { public static of<TVal>(val: TVal) { return new Container(val); } private _value!: T; public constructor(val: T) { this._value = val; } public map<TMap>(fn: (val: T) => TMap) { return new Container<TMap>(fn(this._value)); } public ap<TMap>(c: Container<(val: T) => TMap>) { return c.map(fn => this.map(fn)); }}
We can use the ...
Read now
Unlock full access