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组件之props,$emit与$on以及slot分发

    组件实例之间的作用域是孤立存在,要让它们之间的信息互通,就必须采用组件的通信方式  props用于父组件向子组件传达信息 1.静态方式 eg: <body> <div id=&quo ...

  2. js禁止页面所有a链接访问

    <script type="text/javascript"> var arr=document.getElementsByTagName("a") ...

  3. Team Service 编译项目并生成项目

    第一步:生成GitHub帐号连接 在Service中选择Github 在弹出的GitHub连接中点击授权,即会弹出另一个窗口,输入Github的用户名及口令,即可授权. 第二步:创建Build定义 解 ...

  4. thinkphp的where方法的使用

    1.Thinkphp中where()条件的使用 总是有人觉得,thinkphp的where()就是写我要进行增加.查询.修改.删除数据的条件,很简单的,其实我想告诉你,where()是写条件语句的,但 ...

  5. 【我要学python】MethodType和isinstance和Type函数

    一.首先来看isinstance: a=6 isinstance(a,int) #返回Ture isinstance(a,str) #返回False isinstance (a,(str,int,li ...

  6. Did Pong Lie? (差分系统 判负环)

    Did Pong Lie? 时间限制: 5 Sec  内存限制: 128 MB提交: 68  解决: 15[提交][状态][讨论版] 题目描述 Doctor Pong has two arrays o ...

  7. Linux命令之killall

    killall [选项] [-signal(信号)] [name] killall发送一条信号给所有允许任意指定命令的进程.如果没有指定信号名,则发送SIGTERM.信号可以是名字或数字,只有信号0( ...

  8. 设计模式-外观模式(Facade Pattern)

    本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ 外观模式简介 外观模式的作用用一句话说就是简化接口,举个例子楼主每次编程的时候都要点开IDE.点 ...

  9. 在spring中手动编写事务

    利用事务模板TransactionTemplate来手动添加事务 public void addRant(Rant rant) { transactionTemplate.execute(-?tran ...

  10. [Atcoder Regular Contest 061] Tutorial

    Link: ARC061 传送门 C: 暴力$dfs$就好了 #include <bits/stdc++.h> using namespace std; typedef long long ...