import { PureEffect } from '@typed/effects' ; import { Arity1 , Arity2 , IO } from '@typed/lambda' ; import { HookEffects , InitialState } from './types' ; import { useMemo } from './useMemo' ; import { useState } from './useState' ; export function * useReducer < E , A , B > ( reducer , seed ) { const [ getState , updateState ] = yield * useState ( seed ) ; const deps = [ reducer , updateState ] as const ; const dispatch = yield * useMemo < unknown , typeof deps , Arity1 < B , PureEffect < A > > > ( createDispatch , deps ) ; return [ getState , dispatch ] as const ; } function createDispatch < A , B > ( reducer , updateState ) { return ( event ) : PureEffect < A > => updateState ( ( state ) => reducer ( state , event ) ) ; }