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. 字符串Hash相关

    其实也并不是什么特别难的算法,但是我个人实在是不太喜欢字符串之类的东西(字符串神马的真的是麻烦),于是一直拖着不想看,然后模板题之类的也懒得做. Hash的思想其实也没什么复杂的,就是给定一系列字符串 ...

  2. org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 32; 元素类型为 "key" 的内容必须匹配 "(column)*"

    报错:部分错误信息,主要查看CauseBy Caused by: org.hibernate.InvalidMappingException: Unable to read XML at org.hi ...

  3. Bzoj3197/洛谷3296 [SDOI2013]刺客信条assassin(树的重心+树Hash+树形DP+KM)

    题面 Bzoj 洛谷 题解 (除了代码均摘自喻队的博客,可是他退役了) 首先固定一棵树,枚举另一棵树,显然另一棵树只有与这棵树同构才有可能产生贡献 如果固定的树以重心为根,那么另一棵树最多就只有重心为 ...

  4. 51nod 1052 (dp)

    最大M子段和 N个整数组成的序列a[1],a[2],a[3],…,a[n],将这N个数划分为互不相交的M个子段,并且这M个子段的和是最大的.如果M >= N个数中正数的个数,那么输出所有正数的和 ...

  5. 初见Python<2>:列表和元组

      1.在python中,最基本的数据结构是序列,序列中每一个元素被分配一个序号,即元素的位置,称为索引.索引从0开始,-1表示倒数第一个元素,-2表示倒数第二个元素,因此既可以是从前到后开始对元素进 ...

  6. [Codeforces-div.1 809C] Find a car

    [Codeforces-div.1 809C] Find a car 试题分析 莫名结论:\(a_{i,j}=(i-1) xor (j-1) +1\) 然后分成\(i\space xor\space ...

  7. Codeforces 610C:Harmony Analysis(构造)

    [题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样 ...

  8. python3-开发进阶补充Django中的文件的上传

    PS:这段时间有点不在状态,刚刚找回那个状态,那么我们继续曾经的梦想 今天我们来补充一下文件的上传的几种方式: 首先我们先补充的一个知识点: 一.请求头ContentType: ContentType ...

  9. [PKUSC2018]真实排名

    [PKUSC2018]真实排名 题目大意: 有\(n(n\le10^5)\)个人,每个人有一个成绩\(A_i(0\le A_i\le10^9)\).定义一个人的排名为\(n\)个人中成绩不小于他的总人 ...

  10. (Mark)Myeclipse10.6 下怎么安装Jad插件

    Jad是java的反编译工具,是命令行执行,反编译出来的源文件可读性较高.可惜用起来不太方便.还好找到eclipse下的插件,叫jadclipse,安装好之后,只要双击.class文件,就能直接看源文 ...