This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type nonrec t('a) = list('a); | |
let rec dropWhile = (t, ~f) => | |
switch (t) { | |
| [] => [] | |
| [x, ...rest] => | |
if (f(x)) { | |
dropWhile(rest, ~f); | |
} else { | |
t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let try_finally = (~always, f) => | |
switch (f()) { | |
| x => | |
always(); | |
x; | |
| exception e => | |
always(); | |
raise(e); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************/ | |
/* */ | |
/* OCaml */ | |
/* */ | |
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ | |
/* */ | |
/* Copyright 1996 Institut National de Recherche en Informatique et */ | |
/* en Automatique. */ | |
/* */ | |
/* All rights reserved. This file is distributed under the terms of */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************/ | |
/* */ | |
/* OCaml */ | |
/* */ | |
/* Gabriel Scherer, projet Parsifal, INRIA Saclay */ | |
/* */ | |
/* Copyright 2019 Institut National de Recherche en Informatique et */ | |
/* en Automatique. */ | |
/* */ | |
/* All rights reserved. This file is distributed under the terms of */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************************************/ | |
/* */ | |
/* OCaml */ | |
/* */ | |
/* Simon Cruanes */ | |
/* */ | |
/* Copyright 2017 Institut National de Recherche en Informatique et */ | |
/* en Automatique. */ | |
/* */ | |
/* All rights reserved. This file is distributed under the terms of */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Typeclasses; | |
// a binary search tree is a binary tree that holds order-able members and | |
// keeps lesser values on the left and greater or equal values on the right | |
module Make = (Order: Ord) => { | |
type t = | |
| Empty | |
| Node(t, Order.t, t); | |
// O(log n) operation to add a new value in a valid position in the tree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ordering = | |
| Greater | |
| Less | |
| Equal; | |
// ORD typeclass / interface module | |
module type ORD = { | |
type t; | |
let compare: (t, t) => ordering; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pure a = Some a |> Js.Promise.resolve | |
let fail _ = None |> Js.Promise.resolve | |
let (>=>) x y a = | |
x a | |
|> Js.Promise.then_ ( | |
function | |
| None -> None |> Js.Promise.resolve | |
| Some s -> y s | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Regular Expressions Cheat Sheet | |
> A regular expression specifies a set of strings that matches it. This cheat sheet is based off Python 3's Regular Expressions (http://docs.python.org/3/library/re.html) but is designed for searches within Sublime Text. | |
> Special Characters | |
\ Escapes special characters or signals a special sequence. | |
. Matches any single character except a newline. | |
^ Matches the start of the string. | |
$ Matches the end of the string. | |
* Greedily matches 0 or more repetitions of the preceding RE. | |
*? Matches 0 or more repetitions of the preceding RE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let object1 = {}; | |
// object1.property1 = 42; | |
// console.log(object1.hasOwnProperty('property1')); | |
// // expected output: true | |
// console.log(object1.hasOwnProperty('toString')); | |
// // expected output: false | |
// console.log(object1.hasOwnProperty('hasOwnProperty')); |