Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include $(GOROOT)/src/Make.$(GOARCH) | |
TARG=kademlia | |
GOFILES=\ | |
nodeid.go\ | |
routingtable.go\ | |
contact.go\ | |
kademlia.go | |
include $(GOROOT)/src/Make.pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
//function types | |
type mapf func(interface{}) interface{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val a : Option[String] = Some("333") | |
//a: Option[String] = Some(333) | |
a.filter(_.length > 1).map(_.length) | |
//Option[Int] = Some(3) | |
a.filter(_.length > 6).map(_.length) | |
//Option[Int] = None | |
//filter and map function is just for Option type it's just a monad | |
//def filter(p: A => Boolean): Option[A] | |
//def map[B](f: A => B): Option[B] |
Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.tabclicktime.update( | |
{tabid: 8}, | |
{$set: {title: "电视剧"}}, | |
{multi: true} | |
); | |
//-1 -> desc 1 -> asc | |
db.tabclicktime.find({tabid: 8}).sort({timestamp: -1}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [expression (read-string "(+ 1 2 3 4 5)")] | |
(cons (read-string "*") | |
(rest expression))) | |
;;=> (* 1 2 3 4 5) | |
(eval *1) | |
;;=> 120 | |
(let [expression '(+ 1 2 3 4 5)] | |
(cons '* (rest expression))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix | |
;; and optionally can refer functions to the current ns. | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; | |
;; * :refer-clojure affects availability of built-in (clojure.core) | |
;; functions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;fp语言之所以有抽象能力或者说非fp语言是告诉机器如何一步一步解决问题 而fp语言是向机器描述问题 然后让机器给我们答案其中一个语言原语就是高阶函数 也就是函数可以被当做参数和返回值 还有闭包的存在 函数不再是对象的附属 而是独立的个体 甚至LC中 只有单参函数这一个基本元素却能做到图灵完备 正所谓大道至简 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn fizzbuzz [n] | |
(let [all-nums (range 0 n) | |
folder (fn [fb-str p-num fb-coll] | |
(mapcat (fn [x] (cons fb-str (rest x))) | |
(partition-all p-num fb-coll))) | |
fizz (folder "fizz" 3 all-nums) | |
buzz (folder "buzz" 5 fizz) | |
fizzbuzz (folder "fizzbuzz" 15 buzz)] | |
fizzbuzz)) |
OlderNewer