zoukankan      html  css  js  c++  java
  • [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)
    )
  • 相关阅读:
    面试
    vue axios 应用
    3D全景之ThreeJs
    css垂直居中
    事件处理过程中遇到的问题
    文字溢出
    jquery: 偏移量计算
    jquery: sand picture
    jquery: update carousel logic & animate
    jquery: carousel arrow click
  • 原文地址:https://www.cnblogs.com/Answer1215/p/10356417.html
Copyright © 2011-2022 走看看