- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有这段 clojure
代码:
(def up (memfn toUpperCase))
(str "\n" (apply str (interpose "\n" (map up '("one" "two")))) "\n"); "\nONE\nTWO\n"
这段代码完全按照它应该做的去做:获取一个字符串列表,每个字符串都大写,然后用 \n
(前后加上)将每个字符串括起来。
但必须有一种方法可以用更优雅的方式来编写它。请帮忙。
最佳答案
你可以合并 map 并插入:
(apply str "\n" (map #(str (up %) "\n") '("one" "two")))
另外,不一定更优雅,有点像 timtowdi 的精神:
(clojure.pprint/cl-format false "~%~{~:@(~A~)~%~}" '("one" "two"))
参见 practical common lisp有关 cl 格式字符串的教程。
关于clojure - 在 clojure 中,映射和字符串化 : make it simpler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9284630/
我是正则表达式新手。我有一个名为 encryptId 的字符串(不包含 |),我想在该字符串的每 20 个字符后附加 | 字符,使用Java 中的 encryptId.replace/replaceA
我需要在所有使用非单词字符的地方将查询拆分为单词。例如: query = "I am a great, boy's and I like! to have: a lot-of-fun and @do$
我需要列表的HashMap。通常我这样做: val lists = mutable.HashMap[String,List[Int]]() { override def default(key:
我有一本混合了字符串和列表的字典: sample_dict = {'numbers': [1, 2, 3], 'ref': 'some text'} 目标是将其组合并“扁平化”为可迭代的单个字典,然后
我一直在 Internet 上寻找可以实现此目的的 NPM 包,但一直找不到。 从表面上看,我要寻找的东西非常简单。一个 cron 库,可以将每月的 cron 作业转换为人类可读的文本,同时保持简单。
我有一个 kubernetes 集群。 我可以轻松连接到远程容器,并运行连接到实时生产 erlang 节点的 shell 节点: $ kubectl exec myapp-2431125679-cwq
考虑: >>>jr.operators.values_list('id') [(1,), (2,), (3,)] 如何进一步简化为: ['1', '2', '3'] 目的: class Activit
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭 8 年前。 Improve
映射和字符串化 我有这段 clojure 代码: (def up (memfn toUpperCase)) (str "\n" (apply str (interpose "\n" (map up
为了掌握 PyTorch(以及一般的深度学习),我首先研究了一些基本的分类示例。一个这样的例子是对使用 sklearn 创建的非线性数据集进行分类(完整代码可作为笔记本 here 获得) n_pts
我经常遇到同样的流程问题:我将某些内容注释为 ?type 并忘记它接受 null 所以当我做这样的事情时: function foo(data: string = '') {} function ba
我有大量的物体(首先是球)在空间中逐步移动,一次一个,并且不应重叠。目前,对于每一个 Action ,我都会检查是否与其他所有对象发生碰撞。 Several other questions here然
我经常通过向其添加自引用(“自反”)类型参数约束来使一个简单的接口(interface)变得更加复杂。例如,我可能会这样: interface ICloneable { ICloneable
我不太明白为什么 splay 树数据结构中的旋转不仅要考虑评级节点的父节点,还要考虑祖父节点(zig-zag 和 zig-zig 操作)。为什么以下内容不起作用: 例如,当我们向树中插入一个新节点时,
我不太明白为什么 splay 树数据结构中的旋转不仅要考虑评级节点的父节点,还要考虑祖父节点(zig-zag 和 zig-zig 操作)。为什么以下内容不起作用: 例如,当我们向树中插入一个新节点时,
我一直在寻找有关持久实时可链接双端队列的工作。有多种方法对双端队列的连接具有对数复杂性,有些方法具有摊销的恒定时间实现,但具有恒定时间连接的实时(非摊销)双端队列要少得多。 著名的实时可连接双端队列是
我是一名优秀的程序员,十分优秀!