Skip to content

Instantly share code, notes, and snippets.

View andredublin's full-sized avatar
🐝
buzz

Andre Dublin andredublin

🐝
buzz
View GitHub Profile
@andredublin
andredublin / material.fs
Created September 23, 2016 20:53
idea for websharper material design ui library
open WebSharper.UI.Next.Client
open WebSharper.UI.Next
open WebSharper.UI.Next.Html
module Material =
module Typography =
let flowText content = pAttr [ attr.``class`` "text-flow" ] [ text content ]
module Table =
type TableType =
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MyActivity">
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
@andredublin
andredublin / isimage.fs
Created August 8, 2016 20:48
checks the extension of a file name
type FileExtension =
|PNG
|JPG
|GIF
|RAW
|BMP
|SVG
|PSD
type IsImageType =
@andredublin
andredublin / either.js
Last active May 17, 2016 19:55
either js
// Left represents error or bad case
var Left = function(x) {
this.__value = x;
};
Left.of = function(x) {
return new Left(x);
};
Left.prototype.map = function(f) {
@andredublin
andredublin / maybe.js
Last active May 17, 2016 19:29
maybe in js
var Maybe = function(x) {
this.__value = x;
};
Maybe.of = function(x) {
return new Maybe(x);
};
Maybe.prototype.isNothing = function() {
return (this.__value === null || this.__value === undefined);
@andredublin
andredublin / applicative.js
Created May 17, 2016 14:25
js applicative
var add = (x, y) => x + y
add(Identity.of(2), Identity.of(3)); // "[object Object][object Object]"
var map = curry(function(f, ary) {
return ary.map(f)
});
var identityOf2 = map(add, Identity.of(2));
// Identity(add(2))
@andredublin
andredublin / compmap.js
Created May 17, 2016 01:18
composition and map
// composition = f(g(x))
var compose = function(f, g) {
return function(x) {
return f(g(x));
}
}
var squareAdd10 = compose(square, add10);
[1, 2, 3, 4, 5].map(squareAdd10); // 11, 14, 19, 26, 35
// or
@andredublin
andredublin / mapid.js
Created May 17, 2016 00:42
js map identity
var id = x => x
var xs = [1, 2, 3, 4, 5].map(id(x));
@andredublin
andredublin / selfmap.js
Created May 17, 2016 00:33
self mapping object
var Person = function (name) {
this.name = name;
}
// ('a -> 'b -> Person<'b>)
Person.prototype.map = function (f) {
return new Person(f(this));
}
var me = new Person("Andre");
@andredublin
andredublin / map.txt
Last active May 17, 2016 00:08
mapping fsharp
F#
let xs = List.map (fun x -> x * 2) [1; 2; 3; 4; 5]
C#
var xs = Enumerable.Range(1, 5).Select(x => x * 2)
JS
var xs = [1, 2, 3, 4, 5].map(function(x) { return x * 2 })