- fp-ts ( Functional programming in TypeScript)
- io-ts (IO decoders/encoders)
- io-ts-types (A collection of runtime types and combinators for use with io-ts)
- io-ts-codegen (Code generation for io-ts)
- monocle-ts (Functional optics: a (partial) porting of scala monocle to TypeScript)
- typelevel-ts (Type level programming in TypeScript)
- fp-ts-routing (A type-safe bidirectional routing library for TypeScript)
- money-ts (TypeScript library for type-safe and lossless encoding and manipulation of world currencies and precious metals)
- hyper-ts (Type safe middleware architecture for HTTP servers)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Option } from '@fp-ts/data/Option' | |
import * as O from '@fp-ts/data/Option' | |
import * as S from '@fp-ts/data/String' | |
import produce from 'immer' | |
import * as Optic from '@fp-ts/optic' | |
import * as StringOptic from '@fp-ts/optic/data/String' | |
import { pipe } from '@fp-ts/data/Function' | |
// let's say we want to uppercase the second item of the array | |
interface S { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from http://code.slipthrough.net/2016/08/10/approximating-gadts-in-purescript/ | |
import { Kind, URIS } from 'fp-ts/lib/HKT' | |
import { URI } from 'fp-ts/lib/Identity' | |
import { identity } from 'fp-ts/lib/function' | |
// ------------------------------------------ | |
// Leibniz | |
// ------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as t from 'io-ts' | |
import * as React from 'react' | |
import { render } from 'react-dom' | |
type Field = t.StringType | t.NumberType | t.BooleanType | |
interface Form extends t.InterfaceType<{ [key: string]: Field }> {} | |
const toReactElement = (f: Form | Field): React.ReactElement<any> => { | |
// f is a tagged union | |
switch (f._tag) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { log } from 'fp-ts/lib/Console' | |
import { Type, URIS } from 'fp-ts/lib/HKT' | |
import { none, Option, some } from 'fp-ts/lib/Option' | |
import { randomInt } from 'fp-ts/lib/Random' | |
import { fromIO, Task, task, URI as TaskURI } from 'fp-ts/lib/Task' | |
import { createInterface } from 'readline' | |
// | |
// helpers | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { log } from 'fp-ts/lib/Console' | |
import { none, Option, some } from 'fp-ts/lib/Option' | |
import { randomInt } from 'fp-ts/lib/Random' | |
import { fromIO, Task, task } from 'fp-ts/lib/Task' | |
import { createInterface } from 'readline' | |
// | |
// helpers | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from http://lukajcb.github.io/blog/functional/2018/01/03/optimizing-tagless-final.html | |
import { Applicative, Applicative1 } from 'fp-ts/lib/Applicative' | |
import { Apply, Apply1, Apply2C, applySecond, liftA4 } from 'fp-ts/lib/Apply' | |
import * as array from 'fp-ts/lib/Array' | |
import * as const_ from 'fp-ts/lib/Const' | |
import { HKT, Type, Type2, URIS, URIS2 } from 'fp-ts/lib/HKT' | |
import { IO, io, URI as IOURI } from 'fp-ts/lib/IO' | |
import { Option, some } from 'fp-ts/lib/Option' | |
import { getProductSemigroup, Semigroup } from 'fp-ts/lib/Semigroup' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import type { Monad } from 'fp-ts/lib/Monad' | |
import type { HKT } from 'fp-ts/lib/HKT' | |
import { liftA2 } from 'fp-ts/lib/Apply' | |
import { flatten } from 'fp-ts/lib/Chain' | |
// Adapted from https://tech.iheart.com/why-fp-its-the-composition-f585d17b01d3 | |
interface MonadUser<M> extends Monad<M> { | |
validateUser<U, L>(token: string): HKT<M, U, L, string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import type { Option } from 'fp-ts/lib/Option' | |
import type { Lazy } from 'fp-ts/lib/function' | |
import type { Monad } from 'fp-ts/lib/Monad' | |
import * as optionT from 'fp-ts/lib/OptionT' | |
import { array } from 'fp-ts/lib/Array' | |
// If M<A> is a monad then M<Option<A>> is a monad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import type { Free } from 'fp-ts/lib/Free' | |
import { liftF } from 'fp-ts/lib/Free' | |
import { Identity, identity } from 'fp-ts/lib/Identity' | |
// Creating set of instructions (AST) | |
export class Write<A> { | |
+_tag: 'Write' = 'Write'; |
NewerOlder