Skip to content

dot notation does not work in partial application, function composition #27

@sirpengi

Description

@sirpengi

From the docs, you can chain dot notation in the following way:

ki require core
var r1 = ki (threadf "lol r1" (.toUpperCase) (.trim));
console.log(r1); // "LOL R1"

However, sometimes you want to move this behavior into a function for reuse. Honestly I feel this should work, but it doesn't compile:

var r2 = ki (comp (.toUpperCase) (.trim));
// Unexpected token .

(Neither does (comp .toUpperCase .trim), but that fails with a runtime error)

If you want the same behavior composed, or partially applied, you have to do the following:

var toUpper = function(x){ return x.toUpperCase(); };
var toTrim = function(x){ return x.trim(); };
var r3 = ki (curry pipeline toUpper toTrim);
console.log(r3("lol r3")); // "LOL R3"
var r4 = ki (comp toUpper toTrim);
console.log(r4("lol r4")); // "LOL R4"

On a related note, threadf also doesn't work with curry. The following compiles but results in a runtime error:

var r5 = ki (curry threadf toUpper toTrim);
console.log(r5("lol r5"));
// ReferenceError: threadf is not defined

It kind of makes sense if you think of threadf as a special form, but it doesn't appear dot notation should be. Dot notation works as an argument to threadf, but not in any other situations?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions