我只是想对我的Haskell代码进行一般性改进,并且想知道以下函数是否可以无点编写?主要是出于好奇心的缘故.
给出了我们想要在我们中使用的两个函数filter:
isZero = (==0)
isOne = (==1)
Run Code Online (Sandbox Code Playgroud)
我们如何在我们的设计示例中使用这两个函数,但是使其无点?
filter (\x -> isZero x || isOne x) [0..100]
Run Code Online (Sandbox Code Playgroud) 目前我正在使用JavaScript的本机sort()方法在Ember中进行排序,但实际上我知道我应该使用Ember自己的排序,但不幸的是我完全不知道如何使用它.
我不想浪费人们的时间为我解释(除非你是一个受虐狂),但如果有人知道如何在EmberJS中对一组模型进行排序的精彩文章,那么我们将不胜感激!
目前我有类似下面的内容,我只是在实现使用本机排序再次进行排序,但我在那里停下来因为我想学习正确的方法.
SortOption: Ember.View.extend(
{
template: Ember.Handlebars.compile('<li><a href="javascript:void(0);">{{ option }}</a></li>'),
option: null,
click: function()
{
var rootView = this.nearestWithProperty('people');
var sortBy = this.get('option');
var sorted = rootView.get('people').orderBy('formalName');
rootView.set('people', sorted)
}
})
Run Code Online (Sandbox Code Playgroud) 我发现很难找到任何关于它的东西Ember.Deferred.我查看了EmberJS的源代码,因此我理解了它的方法.我也发现它与承诺模式有关.但是,关于这个最近添加的mixin的任何进一步信息将不仅仅是赞赏!
我经常发现自己必须明确指定return将表达式包装在其中IO/Maybe/Either......但我确信必须有一种更好的方法来使其无点.
例如:
countLines :: FilePath -> IO Int
countLines file = readFile file >>= countLines
where countLines = (\d -> return $ (length . lines) d)
有没有办法实现功能的无点样式countLines?为每一步写lambda >>=是令人厌倦的.