Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了[Functional Programming] liftA2 and converge大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

Sometimes I am confused with ‘liftA2‘ and ‘converge‘ functions.    Main difference between those is that:   liftA2 takes applicative functor as second and third arguements, for example, array   conver

Sometimes I am confused with ‘liftA2‘ and ‘converge‘ functions. 

 

@H_47_18@main difference between those is that:

  liftA2 takes applicative functor as second and third arguements,for example,array

  converge takes functions as second and third arguements

// liftA2 :: applicative m => (a -> b -> C) -> m a -> m b -> m c
// converge :: (b -> c -> d) -> (a -> b) -> (a -> C) -> a -> d

 

// liftA2 :: applicative m => (a -> b -> C) -> m a -> m b -> m c
// converge :: (b -> c -> d) -> (a -> b) -> (a -> C) -> a -> d
const { option,curry,liftA2,converge } = require("crocks");
const { getState } = require("../../Helper");

// getColors :: () -> State AppState [String]
const getColors = () => getState("colors").map(option([]));

// getShapes :: () -> State AppState [String]
const getShapes = () => getState("shapes").map(option([]));

// buildCard :: String -> String -> Card
const buildCard = curry((color,shapE) => ({
  id: `${Color}-${shapE}`,color,shape
}));

// buildCards :: [String] -> [String] -> [Card]
const buildCards = liftA2(buildCard);

// generateCards :: () -> State AppState [ Card ]
const generateCards = converge(liftA2(buildCards),getColors,getShapes);

module.exports = {
  generateCards
};

大佬总结

以上是大佬教程为你收集整理的[Functional Programming] liftA2 and converge全部内容,希望文章能够帮你解决[Functional Programming] liftA2 and converge所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。