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
#!/usr/bin/env guile | |
!# | |
(use-modules ((srfi srfi-1) #:select (fold))) | |
;;; An IO monad is a function which has no parameters. | |
(define (io-unit x) (lambda () x)) | |
;;; The bind function. |
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
from collections.abc import Callable | |
from dataclasses import dataclass | |
import traceback | |
@dataclass(frozen=True) | |
class IO: | |
_action: Callable | |
allowedExceptions: tuple = () |
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
#!/usr/bin/env lua | |
local IO | |
IO = { | |
-- Class method. Create an IO that does nothing and returns x. | |
unit = function(x) | |
return IO(function() return x end) | |
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
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) | |
func show5(f func() int) { | |
for i := 0; i < 5; i++ { | |
fmt.Println(f()) |
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' | |
const blacklist = [ | |
'codegolf.stackexchange.com', | |
'puzzling.stackexchange.com', | |
] | |
/* | |
Move all children of node to right before node. | |
*/ |
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
#!/usr/bin/env python3 | |
# John's version. | |
def shuffle(deck): | |
return [e for l in [a for a in zip(deck[:(len(deck)//2)], deck[(len(deck)//2):])] for e in l] | |
# Slightly simplified. Above, the inner comprehension has just "a for a" with no | |
# "if" at the end, so we can reduce it down to just the iterator. |