【问题标题】:How to use pure FP (ramda or similar) to solve practical plasma cutting如何使用纯FP(ramda或类似)解决实际等离子切割
【发布时间】:2018-12-06 12:47:47
【问题描述】:

我有一个非常实际的问题,即在图案中生成等离子切割线。见附图

我觉得这将是纯函数式编程技术的一个很好的演示,如果有人愿意分享使用 ramda 或类似库的解决方案,因为我正在尝试学习以 FP 方式解决问题,但老实说,我什至没有知道从哪里开始

// arrays a and b will always have same size, but number of points vary from cut to cut

let a = ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']    
let b = ['B0','B1', 'B2', 'B3', 'B4', 'B5']

// need to make array c combining the two arrays in the following pattern
c = ['A0', 'A1', 'B1', 'B2', 'A2', 'A3','B3', 'B4', 'A4', 'A5' ...]

【问题讨论】:

  • 开始:zipWith(concat, chunksOf(2, lineA), chunksOf(2, tail(lineB)))

标签: functional-programming ramda.js enumerable


【解决方案1】:

感谢 Bergi 的带领,我今天学到了很多关于 FP 的知识。 使用 ramda 我让它工作了

let a = ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']    
let b = ['B0','B1', 'B2', 'B3', 'B4', 'B5']
let c = flatten(zipWith(concat, splitEvery(2, a), splitEvery(2, tail(b))))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2022-10-24
    • 2019-03-19
    相关资源
    最近更新 更多