Skip to content

Instantly share code, notes, and snippets.

View awto's full-sized avatar

Vitalii Akimov awto

View GitHub Profile
@awto
awto / DoubleCont.hs
Created November 15, 2012 17:51
shift/reset via double CPS transform
module DoubleCont where
import Control.Monad.Cont
reset :: ContT a (ContT r m) a -> ContT b (ContT r m) a
reset e = ContT $ \k ->
ContT $ \m ->
runContT (runContT e return)
(\r -> runContT (k r) m)
@awto
awto / mostburrido.js
Last active May 28, 2016 10:16
most used with burrido as do notation
/**
* This demonstrates problems of using burrido with most (and in fact with any
* other multi-answer monads). It works only if `most` doesn't contain other
* effect besides pure stream comprehension effects, or effects we don't care
* about.
*/
import {from,of,fromPromise} from 'most'
import Monad from 'burrido'
const MM = Monad({
@awto
awto / mostmf.js
Last active May 28, 2016 10:12
most used with mfjs for do notation
import {from,of,fromPromise,Stream} from 'most'
const M = require('@mfjs/core')
import CC from '@mfjs/cc'
M.profile('regenerator')
const MM = CC.makeMonad(Stream.prototype.chain,of)
let cnt = 0
function updateDb() {
@awto
awto / rxburrido.js
Last active May 28, 2016 11:16
rxjs used with burrido as do notation
/**
* This demonstrates problems of using burrido with most (and in fact with any
* other multi-answer monads). It works only if `most` doesn't contain other
* effect besides pure stream comprehension effects, or effects we don't care
* about.
*/
import {Observable} from 'rx'
import Monad from 'burrido'
const { just: pure, fromPromise,from } = Observable
@awto
awto / rxmj.js
Created May 28, 2016 11:12
rx with mfjs for do notation
import {Observable} from 'rx'
const M = require('@mfjs/core')
const MM = require('@mfjs/rx')()
M.profile('regenerator')
const { just: pure, fromPromise,from } = Observable
let cnt = 0
function updateDb() {
return new Promise(resolve => {
@awto
awto / consume.js
Created December 31, 2017 17:55
decoupling article - consume
async function consume(input) {
for await(const i of input) {}
}
@awto
awto / main.js
Last active January 6, 2018 11:52
decoupling article - main no generators
function main(state) {
for(;;) {
switch(state.control) {
case "init":
state.action = "read"
state.control = "loop1"
return
case "loop1":
const i = state.value
if (i.type === "pointerdown") {
@awto
awto / consume.js
Created December 31, 2017 17:59
decoupling article - consume transpiled
async function consume(input) {
const iter = input[Symbol.asyncIterator]()
for(let i;(i = await iter.next()).done;) {}
}
@awto
awto / animRemove.js
Created December 31, 2017 20:30
decoupling article - animRemove
async function* animRemove(input) {
for await(const i of input) {
if (i.type === "remove") {
const el = i.element
const box = el.getBoundingClientRect()
for await(const j of anim()) {
el.style.width = `${box.width*(1-j)}px`
el.style.height = `${box.height*(1-j)}px`
el.style.top = `${box.y+window.pageYOffset+box.height*j/2}px`
el.style.left = `${box.x+window.pageXOffset+box.width*j/2}px`
@awto
awto / stopThread.js
Created December 31, 2017 20:30
decoupling article - stopThread
async function* stopThread(input) {
for await(const i of input) {
yield i
if (i.type === "drop" || i.type === "dragcancel" || i.type === "remove")
break
}
}