Skip to content

Instantly share code, notes, and snippets.

View NotIntMan's full-sized avatar

Dmitry Demin NotIntMan

  • Russian Federation, Novosibirsk
View GitHub Profile
@NotIntMan
NotIntMan / trans.ts
Created August 21, 2020 07:52
Transduction over arrays. Why doesn't we still use it?
interface Transducer<T, R> {
(source: Iterable<T>): Iterable<R>;
}
class IterableTransductor<T> implements Iterable<T> {
constructor(
private readonly source: Iterable<T>,
) {
}
@NotIntMan
NotIntMan / README.MD
Last active February 22, 2016 20:19
Promisify IPC

Promisify IPC

What is this?

This is Promise-style wrapper (or layer, if you want) for event-channel. Why did I write this? Because I need to get promised calls through IPC-channel.

P.S. IPC is channel, which implementing EventEmitter interface and gives us a way to communicate between node-processes

How to use

@NotIntMan
NotIntMan / denodeify.js
Last active November 7, 2015 07:58
Little module to let callBack'ed functions return a Promise.
'use strict'
function denodeifySpecial (func, callBack) {
return function () {
let _this = this
let len = arguments.length
let args = new Array(len+1)
for (let i = 0; i<len; i++)
args[i] = arguments[i]
return new Promise((resolve, reject)=> {
@NotIntMan
NotIntMan / sync.js
Last active November 7, 2015 07:56
Just a little module to provide Async functions using ES6 Generators without BabelJS or others transpilers.
'use strict'
function Sync(fn,args) {
return new Promise(function(resolve, reject) {
let gen, call, callNext, callThrow
call = function(isErr, arg) {
let result
try {
if (isErr)
result = gen.throw(arg)