打字稿中的链接函数

exi*_*onX 1 javascript chaining typescript lodash

我有一些格式化函数应该应用于某些字符串:

const limitSize = (limit: number): ((str: string) => string) => {
  return (str: string) => str.substring(0, limit)
}

const replaceNewLine = (replaceWith: string): ((str: string) => string) => {
  return (str: string) => str.replace(/\n/g, replaceWith)
}
Run Code Online (Sandbox Code Playgroud)

它们都返回一个可以应用于字符串的函数

如何将它们链接在一起,以便结果也返回一个可以应用于字符串的函数?

是否有我缺少的 lodash 实用程序?

jus*_*est 5

我认为你需要流动Lodash的功能或Ramda的

function square(n) {
  return n * n;
}
 
var addSquare = _.flow([_.add, square]);
addSquare(1, 2);
// => 9
Run Code Online (Sandbox Code Playgroud)