我认为这应该很容易,但我今天的日期无法在使用Liquid标记的Jekyll页面中显示.根据文档,我应该能够这样做以获得这个日期的年份:
{{ 'now' | date: "%Y" }}
Run Code Online (Sandbox Code Playgroud)
但所有渲染的都是字符串now,而不是任何格式化的日期.我究竟做错了什么?
我想知道这里的最佳做法.如果工厂方法无法创建任何内容,那么返回null是一种好习惯吗?这是一个例子:
ICommand command = CommandFactory.CreateCommand(args);
if (command != null)
command.Execute();
else
// do something else if there is no command
Run Code Online (Sandbox Code Playgroud)
NullCommand我想,另一种方法是返回一个或某个东西,但最佳做法是什么?
我仍在研究 Haskell,尤其是 IO monad。
我有一个目录路径列表,例如,
["/some/path", "/another/path", "/yet/another/path", "/still/more"]
并且我想将此列表映射到每个路径的完全限定内容列表中(没有.和..),如下所示:
["/some/path/file.1", "/some/path/somedir", "/some/path/file.2", "/another/path/file.a", "/another/path/a/directory", "/another/path/file.b", "/still/more/file.alpha", ...]
我想我可以用某种双映射来做到这一点,就像这样:
pathItems <- mapM (\pd -> MapM (\contents -> (pd </>) contents) (getDirectoryContents pd) pathDirs
但这不起作用。我得到的错误是这样的:
程序.hs:27:56:
无法将类型“[]”与“IO”匹配
预期类型:IO 字符
实际类型:文件路径
在表达式中: (pd </>) 内容
在‘mapM’的第一个参数中,即
`(\ 内容 -> (pd ) 内容)'
程序.hs:27:84:
无法匹配预期类型“[FilePath]”
实际类型为“IO [FilePath]”
在'mapM'的第二个参数中,即
`(getDirectoryContents pathDir)'
在表达式中:
地图M
(\ 内容 -> (pd </>) 内容)
(getDirectoryContents pd)
我已经在Scheme,Racket和Clojure中注意到表达式(在这里使用Clojure)(and true '())评估()并(and '() true)评估为true.这不仅适用于空列表,也适用于任何列表.
但是在GNU CLISP和Emacs Lisp中,也(and t '())评估nil和(and '() t)评估nil,但(and t '(1 2 3))评估(1 2 3)和(and '(1 2 3) t)评估t.
这里发生了什么?
我有一张矢量地图,如下所示:
{2 ["a" "c" "b"], 1 ["z" "y" "x"]}
Run Code Online (Sandbox Code Playgroud)
我想得到一个按key排序的map,然后每个对应的vector也进行排序,像这样:
{1 ["x" "y" "z"], 2 ["a" "b" "c"]}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过执行按键排序(into (sorted-map) themap),并且我知道我可以为 提供换能器into,但是我对换能器的确切外观很不了解。这是我试过的换能器:
(defn xform [entry]
(vector (first entry) (vec (sort (second entry)))))
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将其应用到我的地图时,出现以下异常:
java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.core$conj__4345
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它发挥作用?有没有比使用into换能器更好的方法?
我最近在Exercism上为ISBN Verifier练习编写了一个解决方案,当我通过pointfree.io运行这个函数时:
\c -> isDigit c || c == 'X'
Run Code Online (Sandbox Code Playgroud)
我回来了:
liftM2 (||) isDigit ('X' ==)
Run Code Online (Sandbox Code Playgroud)
为什么pointfree.io选择liftM2从Control.Monad,而不是liftA2从Control.Applicative?