[Functional Programming ADT] Debug a Functional JavaScript composeK Flow
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Functional Programming ADT] Debug a Functional JavaScript composeK Flow相关的知识,希望对你有一定的参考价值。
When using ADTs in our code base, it can be difficult to use common debugging tools like watches and breakpoints. This is mainly due to the common pattern of using compositions and other ways of manipulating how functions are called. This can cause us to have to revert to using console logs at the different points in our flow, to peek at how our data is changing over time. When using ADTs this gets even further complicated by the fact that we typically need ways to lift our logging functions into the type.
To get a handle on one way to approach debugging, we’ll look at a logAfter
function that is a must in any Functional Programmer’s toolkit. Using logAfter
we’ll hunt down a bug currently in our code base and once located, squash that bug out of existence.
// logAfter :: (a -> State s b) -> a -> State s b export const logAfter = fn => composeK(liftState(tap(console.log)),fn)
How to use:
// validateAnswer :: String -> State AppState Boolean const validateAnswer = converge( liftA2(equals), logAfter(getHint), logAfter(cardToHint) )
以上是关于[Functional Programming ADT] Debug a Functional JavaScript composeK Flow的主要内容,如果未能解决你的问题,请参考以下文章
python learning Functional Programming.py
Python5 函数式编程(Functional Programming)
[Functional Programming] propSatisfies with implies
[Functional Programming] Arrow Functor with contramap
[Functional Programming + React] Provide a reasonable default value for mapStateToProps in case init
[Functional Programming] Running though a serial number prediction functions for tagging, pairing th