- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Ramda 适合懒人
Ramda 的 transduce
启用 creation of lazy sequences .
一对多R.chain
可以在转换器中用作一对多运算符,如下所示 ( REPL ):
const tapLog = R.tap( (what) => console.log(what) )
const suits = ['♠', '♥', '♦', '♣']
const ranks = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'J', 'Q', 'K', 'A']
const addRank = (suit) => R.map(concat(suit),ranks)
var transducer = R.compose(
R.chain(addRank),
tapLog,
R.take(2)
);
R.into([], transducer, suits);
// => ♠1 // console.log
// => ♠2 // console.log
// => ["♠1", "♠2"]
R.map(concat(suit),ranks)
不会懒惰 - 所有的等级都将被映射(创建中间阵列),只有这样链才会将它们“管道”到传感器序列中。
R.chain
的实现看起来像这样:
var chain = _curry2(_dispatchable(['fantasy-land/chain', 'chain'], _xchain, function chain(fn, monad) {
if (typeof monad === 'function') {
return function(x) { return fn(monad(x))(x); };
}
return _makeFlat(false)(map(fn, monad));
}));
_makeFlat
这会阻止任何懒惰的评估。
最佳答案
您遇到的问题是,尽快R.map(concat(suit),ranks)
遇到,它会立即得到完整的评估。这与_makeFlat
无关您提到的功能,如使用换能器时 _dispatchable
实际上不会调用 R.chain
定义中的函数体而是使用 _xchain
中的换能器定义.
因此,与其生成一个完整的映射列表,不如创建一个新的传感器,我将其命名为 combineWith
。 ,它需要一个类似 concat
的函数在您的示例和列表中,将每个元素与经过转换相结合。我们可以在检查 @@transducer/reduced
时这样做一路上。
const combineWith = (fn, xs) => xf => ({
// proxy both `init` and `result` straight through
// see internal/_xfBase.js
'@@transducer/init': xf['@@transducer/init'].bind(xf),
'@@transducer/result': xf['@@transducer/result'].bind(xf),
// combine the item at each step with every element from `xs`
// using `fn`, returning early if `reduced` is ever encountered
'@@transducer/step': (acc, item) => {
for (const x of xs) {
acc = xf['@@transducer/step'](acc, fn(item, x))
if (acc['@@transducer/reduced']) return acc
}
return acc
}
})
const suits = ['♠', '♥', '♦', '♣']
const ranks = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'J', 'Q', 'K', 'A']
const tapLog = R.tap(console.log.bind(console, 'tapLog'))
const transducer = R.compose(
combineWith(R.concat, ranks),
tapLog,
R.take(2)
)
console.log('result', R.into([], transducer, suits))
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
关于ramda.js - Ramda 的传感器 : Lazy one-to-many branch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47763857/
我试图让 Branch.io 在 Android 上工作,但我遇到了: myapplication.MainActivity cannot be cast to android.app.Applica
当我执行 git branch 时,我知道我在分支 v0.2 上。 git branch v0.1 * v0.2 但是当我执行 git push 时它说“你当前分支的上游分支与你当前分支的名称不
在使用 Git GUI 检查远程分支 releases/rel_5.4.1 之后,当我尝试 push 时看到了这个意外的错误消息: fatal: The upstream branch of your
SO 上有一个相关问题处理如何更改 push 命令的参数以避免出现此消息: fatal: The upstream branch of your current branch does not mat
arc feature [branch-name] 和 git branch [branch-name] 有什么区别? 他们似乎都创建了一个新分支。 最佳答案 arc feature [branch-
FIFO、LIFO 和LC Branch and Bound 有什么区别? 最佳答案 Branch & Bound 通过使用估计边界来限制可能解决方案的数量来发现完整搜索空间内的分支。不同的类型(FI
有人知道这两个切换和跟踪远程分支的命令之间的区别吗? git checkout -b branch origin/branch git checkout --track origin/branch 我
关于 git-svn 工作流程有很多问题,但我一直无法弄清楚这一点: This section of the svn book谈到 SVN 的一个常见做法:创建一个分支,并在主干更新时不断合并主干中的
我正在构建一个控制 git 存储库的 PHP 应用程序。我有一个执行命令 git status 的同步函数,虽然没有返回“你的分支是最新的”,但可能会提前采取必要的行动,比如远程或本地分支。 我还构建
是否可以使用 branch.io 创建自定义链接,例如 https://example.app.link/fzmLEhobLD所以我可以用我的自定义 10 位参数(如 amitpp8888)控制 fz
我从 github 克隆了一个分支,它的名字是 dev。我已经开始使用它, pull 和推送代码更改并确保我的本地存储库与远程存储库保持同步。我要开始实现一个新功能,因此创建了一个新分支,如下所示:
我们有一个发布模型,为简单起见,我们假设每月 1 次。所以,我们通常会去: Jan -> trunk trunk -> Feb trunk trunk et
使用 Branch.io HTTP API 创建的链接不会在 Branch 门户中显示为快速链接。快速链接很方便,因为它们在一个 View 中显示“点击”、“打开”等内容 用于创建链接的 API:li
我创建了一个分支,当我第一次从源代码合并到分支时,出现了一大堆旧的变更集,它说没有合并,但它们在分支之前就存在,我确认它们在那里。 例子: 假设当 Source 中有 9 个变更集时,我从 Sourc
这是关于我为什么这样做 不是 收到错误“致命:当前分支 A 没有上游分支”。 我删除了 远程 分公司 一个 使用命令 git push origin :A . 然后我切换到本地 分支 A 使用命令 g
我正在使用 clover 插件来检查我的 java 代码测试覆盖率。 我为所有行编写了单元测试。当我点击红线时,它显示“true分支执行了2次,分支执行了0次”。这是什么意思?我该如何解决这个问题?
很确定我误解了 git。 我的目标 我在 github 上有一个带有“master”分支的私有(private)存储库。 我还想有一个生产分支,我会将所有更改从 master 推送到该分支。 然后我想
我将一个相当老的主题分支重新定位到 master 上。由于在 rebase 期间有很多冲突,我想将旧主题分支与 rebased 分支进行比较,以确保我没有意外删除或搞砸主题上的任何更改。我最接近的是比
我正在尝试将我的一个项目推送到 github,但我一直收到此错误: peeplesoft@jane3:~/846156 (master) $ git push fatal: The current b
Jenkins Git 插件根据我的引用规范在控制台输出中生成了以下命令 下面两个命令有什么区别?他们的输出看起来没什么不同。我在下面给出了他们的输出: 命令 1: git fetch --no-ta
我是一名优秀的程序员,十分优秀!