码迷,mamicode.com
首页 > 编程语言 > 详细

[Functional Programming ADT] Debug a Functional JavaScript composeK Flow

时间:2019-02-08 18:34:13      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:javascrip   current   other   ase   dts   nbsp   equal   export   app   

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

标签:javascrip   current   other   ase   dts   nbsp   equal   export   app   

原文地址:https://www.cnblogs.com/Answer1215/p/10356417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!