Skip to content

Instantly share code, notes, and snippets.

@busypeoples
busypeoples / Graph.re
Last active November 18, 2019 21:59
Data Structures in ReasonML: #8 Graph
/* Graph */
exception Not_found;
type nodes = list(int);
type edges = list((int, int));
type graph =
| Empty
| Graph(nodes, edges);
@busypeoples
busypeoples / Heap.re
Last active July 29, 2018 10:43
Data Structures in ReasonML: #7 Heap
/* Heap */
exception Not_Found;
module type Ord = {type t; let compare: (t, t) => int;};
module Integer = {
type t = int;
let compare = (a, b) => a - b;
};
@busypeoples
busypeoples / AvlTree.re
Last active August 7, 2019 06:02
Data Structures in ReasonML: #6 AVL Tree
/* AVL Tree */
/* A balanced Binary Search Tree */
exception Undefined;
module type AvlTree = {
type t = int;
type height = int;
type tree('t) =
| Leaf
| Node(height, tree('t), 't, tree('t));
@busypeoples
busypeoples / LinkedList.re
Last active July 8, 2020 21:56
Data Structures in ReasonML: #5 Linked List
exception Empty_list;
module type LinkedList = {
type t;
type linkedList('t) =
| Empty
| List('t, linkedList('t));
let empty: linkedList('t);
let head: linkedList('t) => 't;
let tail: linkedList('t) => linkedList('t);
@busypeoples
busypeoples / Set.re
Created July 21, 2018 14:30
Data Structures in ReasonML: #3 Set
/* Set */
/* Contains unique elements */
module type Ord = {
type t;
let eq: (t, t) => bool;
let lt: (t, t) => bool;
let leq: (t, t) => bool;
};
module Integer: Ord with type t = int = {
@busypeoples
busypeoples / Stack.re
Created July 20, 2018 09:04
Data Structures in ReasonML: #2 Stack
/* Stack */
/* LIFO: Last In First Out*/
exception Empty;
module type Stack = {
type stack('a) = list('a);
let create: unit => stack('a);
let push: ('a, stack('a)) => stack('a);
let pop: stack('a) => stack('a);
let peak: stack('a) => 'a;
@busypeoples
busypeoples / BinarySearchTree.re
Created July 19, 2018 10:55
Data Structures in ReasonML: #1 Binary Search Tree
/* Binary Search Tree*/
/* Rules:
1. Values from the left node are smaller than the node's own value
2. Values from the right node are larger than the node's own value
// Example
// [] Node
// () leaf
[7]
 / \
[4] [9]
@busypeoples
busypeoples / HashTrie.js
Last active July 16, 2018 18:59
Implementing persistent data structures with HashTries
// @flow
// Immutable Data Implementation
// Based on Hash Tries
// (NOTE: The actual implementation is based on hashed mapped tries!)
// But this can be seen as a basis for the actual implementation.
// This is only for learning purposes!
// Hash Trie or Hash Tree is a persistent data structure, commonly used
// to implement immuable maps.
@busypeoples
busypeoples / BasicTrie.js
Created July 11, 2018 13:51
Basic Trie Implementation including Flow annotations
// @flow
/**
*
* Trie Example
* This is part of a series of examples that will lead to implemeting
* a hashed mapped trie based immutable data structure.
*
*/
@busypeoples
busypeoples / 1_TransformingElementsInReact.md
Last active August 3, 2018 22:23
Transforming Elements in React

Transforming Elements in React

Introduction

Transforming elements can be interesting if you're a library author, but can also be very valuable when writing components to abstract behaviour in your existing code base.

To get a better understanding, we will walkthrough the most important React Top Level API transformation functionalities. React offers a couple of helper functions that we can leverage when for creating and adapting elements, further information is available via the official React documentation.