import { pipe } from 'fp-ts/function' ; import * as IO from 'fp-ts/IO' ; import { Monoid } from 'fp-ts/Monoid' ; import * as R from 'fp-ts/Random' ; export interface Die extends IO . IO < number > { } export const die = ( faces ) : Die => R . randomInt ( 1 , faces ) ; export const modifier = ( n ) => ( die ) : Die => pipe ( die , IO . map ( ( m ) => m + n ) ) ; const liftA2 = < A , B , C > ( f ) => ( fa ) => ( fb ) : IO . IO < C > => pipe ( fa , IO . map ( f ) , IO . ap ( fb ) ) ; export const add = liftA2 ( ( a ) => ( b ) => a + b ) ; export const multiply = ( n ) => ( die ) : Die => pipe ( die , IO . map ( ( m ) => m * n ) ) ; export const monoidDie = { concat : ( first , second ) => pipe ( first , add ( second ) ) , empty : ( ) => 0 } ; const d6 = die ( 6 ) ; const d8 = die ( 8 ) ; const _2d6_1d8_2 = pipe ( d6 , multiply ( 2 ) , add ( d8 ) , modifier ( 2 ) ) ; console . log ( _2d6_1d8_2 ( ) ) ;