From 5d3189fae565458ae5701e7f4fe500150caf3d5f Mon Sep 17 00:00:00 2001 From: Kray-G Date: Fri, 5 Mar 2021 21:53:27 +0900 Subject: [PATCH] added a new Functional. --- lib/std/kxfunctional.kx | 25 ++++++++++++++++++++++++- lib/std/kxstartup.kx | 10 +++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/std/kxfunctional.kx b/lib/std/kxfunctional.kx index 444e9abd0..2fb896a12 100644 --- a/lib/std/kxfunctional.kx +++ b/lib/std/kxfunctional.kx @@ -114,4 +114,27 @@ _function _functional_enumerator(e) { }; } -Functional.enumerable = Functional.Enumerator.create = _functional_enumerator; +Functional.methodMissing = _function(_instance, method, ...a) { + Functional[method] = _function(...args) { + return _function(obj) { + return obj[method](...args); + }; + }; + return Functional[method](...a); +}; + +// The methods in Array such as `map` have to be assigned to this object +// because Array.map will have been called directly instead of this.map +// and methodMissing will not be called. +Array.keySet(Array).filter({ => Array[_1].isFunction }).each { &(method) + Functional[method] = _function(...args) { + return _function(obj) { + return obj[method](...args); + }; + }; +}; + +Functional.enumerable + = Functional.Enumerator.create + = _functional_enumerator + ; diff --git a/lib/std/kxstartup.kx b/lib/std/kxstartup.kx index 85a612fed..d727a25c0 100644 --- a/lib/std/kxstartup.kx +++ b/lib/std/kxstartup.kx @@ -22,6 +22,11 @@ var Xml, Net; Net = _import('kxnet'); SQLite = _import('kxsqlite'); Debugger = _import('kxdebugger'); + using kxsysutil; + using kxstring; + using kxarray; + using kxbinary; + using kxnumeric; using kxisolate; using kxexception; using kxsqlite; @@ -29,11 +34,6 @@ var Xml, Net; using kxnet; using kxenumerable; using kxfunctional; - using kxsysutil; - using kxstring; - using kxarray; - using kxbinary; - using kxnumeric; using kxfile; using kxgetopt; Zip.create = File._zipCreate;