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的更多相关文章

  1. [Functional Programming] Draw Items from One JavaScript Array to Another using a Pair ADT

    We want to be able to pick nine random cards from an array of twelve cards, but can run into problem ...

  2. [Functional Programming ADT] Create State ADT Based Reducers (applyTo, Maybe)

    The typical Redux Reducer is function that takes in the previous state and an action and uses a swit ...

  3. [Functional Programming ADT] Adapt Redux Actions/Reducers for Use with the State ADT

    By using the State ADT to define how our application state transitions over time, we clear up the ne ...

  4. [React + Functional Programming ADT] Create Redux Middleware to Dispatch Actions with the Async ADT

    We would like the ability to group a series of actions to be dispatched with single dispatching func ...

  5. [React + Functional Programming ADT] Connect State ADT Based Redux Actions to a React Application

    With our Redux implementation lousy with State ADT based reducers, it is time to hook it all up to a ...

  6. [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer

    With a well defined demarcation point between Redux and our State ADT based model, hooking up to a R ...

  7. [Functional Programming ADT] Initialize Redux Application State Using The State ADT

    Not only will we need to give our initial state to a Redux store, we will also need to be able to re ...

  8. [Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers

    Redux provides a convenient helper for combining many reducers called combineReducer, but it focuses ...

  9. [React + Functional Programming ADT] Create Redux Middleware to Dispatch Multiple Actions

    We only have a few dispatching functions that need to be known by our React Application. Each one ac ...

随机推荐

  1. Vue结合原生js实现自定义组件自动生成

    就目前三大前端主流数据驱动框架(vue,ng,react)而言,均具有创建自定义组件的api,但都是必须先做到事先写好挂载点,这个挂载点可以是原有静态元素标签也可以是自定义模板:对于多种组件通过同一数 ...

  2. Intellij IDEA 去掉Mapper文件中的背景

    1.在setting中输入:inspection --> SQL 2.去掉背景颜色,Apply即可

  3. Jsonp方式和httpclient方式有什么区别?

    jsonp基于js,解决跨域问题,本质发起ajax情求但是Jsonp只支持get请求. 它不安全,它先解析js,然后发起ajax请求,然后获取到返回值,通过浏览器返回,最后解析. JQuery和Spr ...

  4. C语言数据类型64位和32机器的区别

    C语言编程需要注意的64位和32机器的区别 .数据类型特别是int相关的类型在不同位数机器的平台下长度不同.C99标准并不规定具体数据类型的长度大小,只规定级别.作下比较: 32位平台 char:1字 ...

  5. 【ASP.NET MVC】提高页面加载速度:脚本优化

    在这里我们说一下脚本优化的三个方法: 一.在我们做Web开发的时候,当我们引用Js文件的时候,我们一般会将js文件放在文档的head标签中,这时当页面加载的时候,浏览器会按着由上到下的顺序,当浏览器遇 ...

  6. Django CRM查询 XXX.object.filter() 常用用法总结

    __gt 大于 __gte 大于等于 User.objects.filter(age__gt=10) // 查询年龄大于10岁的用户 User.objects.filter(age__gte=10) ...

  7. HDU 2665.Kth number-可持久化线段树(无修改区间第K小)模板 (POJ 2104.K-th Number 、洛谷 P3834 【模板】可持久化线段树 1(主席树)只是输入格式不一样,其他几乎都一样的)

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. mysql 如何给root用户设置密码

    用root 进入mysql后mysql>set password =password('你的密码');mysql>flush privileges;

  9. Android Theme.AppCompat.Light的解决方法

    styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...

  10. Single Number III(LintCode)

    Single Number III Given 2*n + 2 numbers, every numbers occurs twice except two, find them. Example G ...