Skip to content

Instantly share code, notes, and snippets.

View volodymyrprokopyuk's full-sized avatar

Volodymyr Prokopyuk volodymyrprokopyuk

View GitHub Profile
@volodymyrprokopyuk
volodymyrprokopyuk / kotlin_let_also_run_apply.kt
Created January 22, 2018 10:13
Kotlin let, also, run, apply
package org.vld.kotlin.language
class Demo(private val property: String = "Demo") {
fun runExample() {
// run > transformation function > this > returns new value
val string = "run Kotlin".run {
println(this)
"run Kotlin 1.2.20"
}
var Parent = function(name) { // constructor
this.name = name; // own property
};
// Function.prototype
(function(proto) {
// shared method
proto.toString = function() { return '** Parent ' + this.name; };
})(Parent.prototype);
@volodymyrprokopyuk
volodymyrprokopyuk / promise_utils.js
Last active January 4, 2016 10:06
Promise Utils (JavaScript)
var _ = require('lodash');
var Promise = require('bluebird');
var recursive = function(obj, proc, pred) {
pred = pred || _.partial(_.identity, true);
(function recurse(parent, val, key) {
_.isObject(val) ? _.map(val, _.partial(recurse, val))
: pred(val) && (parent[key] = proc(val));
})(null, obj);
};
@volodymyrprokopyuk
volodymyrprokopyuk / railway_oriented_programming.js
Last active October 6, 2020 04:50
Railway Oriented Programming (JavaScript)
var _ = require('lodash');
var Success = function(success) { this.success = success; };
var Failure = function(failure) { this.failure = failure; };
var bindAll = function(fs) {
var bind = function(res, f) {
return res instanceof Success ? f(res.success) : res;
};
var bindF = function(f) { return _.partial(bind, _, f); };