Skip to content

Instantly share code, notes, and snippets.

View cem2ran's full-sized avatar
⚛️
~ The only constant is change ~

Cem Turan cem2ran

⚛️
~ The only constant is change ~
View GitHub Profile
def unfold[A,S](initial: S)(generateNext: S => Option[(A, S)]): Stream[A] =
generateNext(initial) match {
case Some((first, next)) => cons(first, unfold(next)(generateNext))
case None => empty
}
val fibs =
unfold((0,1)) {
case (f0, f1) => Some((f0, (f1, f0+f1)))
}
const combine = (...arrays)
=> [].concat(...arrays);
const compact = arr
=> arr.filter(el => el);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
)();
@cem2ran
cem2ran / auto_curry.js
Last active December 16, 2015 01:14
Auto-currying for the masses
Function.prototype.curried = function (f=this) {
return (...args) => args.length < f.length
? f.curried(args.reduce((g, arg) => g.bind(null, arg), f))
: f.apply(null, args);
};
<!DOCTYPE html><script src="https://jspm.io/system@0.19.js"></script><script>System.config({transpiler: "babel"});System.import("./index.js");</script><body></body></html>
@cem2ran
cem2ran / qc35_fix.sh
Created September 16, 2016 12:55
Bose QC35 bass distortion on Macbook fix
defaults read com.apple.BluetoothAudioAgent > ~/com.apple.BluetoothAudioAgent.defaults.txt
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Max (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool Min (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool" 80
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Max" 80
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Min" 80
let map = (fn,[head, ...tail]) => head === undefined
? []
: [fn(head), ...map(fn,tail)]
console.log("map(x=>x+1,[1,2,3,4]) :",map(x=>x+1,[1,2,3,4]))
let filter = (predicate, [head, ...tail]) => head === undefined
? []
: predicate(head)
? [head, ...filter(predicate, tail)]

##Monads for functional programming (in Elm)

Adaptation of the examples in Philip Wadler's paper "Monads for functional programming" for the Elm language.

These examples can easily be tried out on the online elm playground: http://elm-lang.org/try

convert "$@" +dither -colors 5 -unique-colors txt: | head -n 2 | tail -n 1 | awk '{ print $3 }'
open Belt.Result;
type options;
module Stdio: {
type t = pri string;
[@bs.inline "inherit"]
let inherit_: t;
@cem2ran
cem2ran / reason-0-60.re
Last active April 16, 2020 09:54 — forked from davidkpiano/ts-0-60.ts
TypeScript from 0 to 60
// No TypeScript, but statically typed
let add = (a, b) => a + b;