Skip to content

Update for my FP implementation yesterday #266

@SilasFan

Description

@SilasFan

昨天我在 #145 的更新大佬好像没有看到,刚好今天上线又看到了 #237 的大佬提到的reduce的实现,所以再更新一下,也用于抛砖引玉吧~~

「添一」 is predefined ahead, in JS might be:

function addOne(x) {
    return x+1;
}

Impletements Array.prototype.map like:
吾有 「甲列」者, 皆「添一」其上,皆 「添一」其上,终得 「乙列」也

As for Array.prototype.reduce, just replace with

Javascript:

var bList = aList.map(addOne).map(addOne);

In Addition, there's a possible implementation for compose:
吾有一数,名之曰 「添五」, 盖合「添一」, 「添一」, 「添一」, 「添一」, 「添一」者也
(The parser translate 吾有一术 to keyword function, so I use 吾有一数)

Javascript:

var addFive = compose(addOne, addOne, addOne, addOne, addOne)

If functions in compose need params, can expand to:
吾有一数,名之曰 「添二」, 盖合「添」于「一」, 「添」于「一」者也
(But I forget whether the syntax is available in Traditional Chinese)

Of course, 「添」 and 「一」 might be:

function add(func) {
    return function(x) {
        return x + func();
    }
}

function one() {
    return 1;
}

最后我想说,这样设计语法的目的也是为了写出短句,emmmm读起来更有节奏感吧🤣

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions