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
class Seq { | |
toArray() { | |
const a = []; | |
for (const x of this) | |
a.push(x); | |
return a; | |
} | |
toString() { | |
return this.toArray().join(' -> '); |
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
'use strict'; | |
var csp = require('plexus-csp'); | |
// Creates a detached (i.e. never yielded) asynchronous task with some error | |
// reporting upon failure. The explicit error handling is necessary because | |
// error propagation to the calling task only works if we yield the result. | |
var detach = function(task) { |
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
Original: | |
.1. | |
.1. | |
.2. | |
.4. | |
.3. | |
.9. | |
.4. | |
.16. | |
[ 1, 1, 2 ] |
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
// Asynchronous Flux-like dispatcher with deadlock prevention via Go-style CSP. | |
// | |
// - my libraries ceci-core and ceci-channel are available from npm | |
// - pre-compile this file with regenerator | |
// - build with webpack or browserify | |
'use strict'; | |
var ceci = require('ceci-core'); | |
var chan = require('ceci-channels'); |
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 tails [s] | |
"The sequence of sequences starting at each position in the given sequence 's'." | |
(lazy-seq (when-let [s (seq s)] | |
(cons s (tails (rest s)))))) | |
(defn reduce-true [f val coll] | |
"A short-circuiting version of 'reduce'. Stops evaluation when the | |
accumulated value is logically false." | |
(let [v (->> (reductions f val coll) | |
(tails) |
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
class Seq | |
attr_reader :first | |
def initialize(first, &rest) | |
@first = first | |
@rest = rest | |
end | |
def rest | |
@rest = @rest.call() |
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
x = [1,2,3,4] | |
x.zip([true]).each do |item, first| | |
puts "\n" unless first | |
puts item | |
end |
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
bounce = (val) -> val = val() while typeof val == 'function'; val | |
factorial = (n) -> | |
fact = (a, n) -> if n > 0 then -> fact a * n, n - 1 else a | |
bounce fact 1, n | |
console.log factorial 10 |
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
# Displays a line of code alongside the type and value of its output. | |
# | |
# For example, the line | |
# | |
# show -> 1 * 2 * 3 | |
# | |
# or, in Javascript | |
# | |
# show( function () { return 1 * 2 * 3 } ) | |
# |
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
def set_cookie(key, value) | |
# This is how one needs to set cookies in Rack::Test. | |
jar.merge "#{key.to_s}=#{value};domain=#{domain};path=/" | |
end | |
def get_cookie(key) | |
jar[key.to_s] | |
end | |
def jar |
NewerOlder