Skip to content

Instantly share code, notes, and snippets.

View idkjs's full-sized avatar

Alain Armand idkjs

View GitHub Profile
@idkjs
idkjs / GroupWhile.re
Created July 1, 2021 14:54
GroupWhile for Rescript/Reason using Belt lib
type nonrec t('a) = list('a);
let rec dropWhile = (t, ~f) =>
switch (t) {
| [] => []
| [x, ...rest] =>
if (f(x)) {
dropWhile(rest, ~f);
} else {
t;
@idkjs
idkjs / try_finally.re
Created June 27, 2021 10:35
try a function example
let try_finally = (~always, f) =>
switch (f()) {
| x =>
always();
x;
| exception e =>
always();
raise(e);
};
@idkjs
idkjs / Str.re
Last active June 24, 2021 11:12
Stdlib.Str.re
/**************************************************************************/
/* */
/* 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 */
@idkjs
idkjs / Either.re
Last active June 24, 2021 10:27
Stdlib.List.re
/**************************************************************************/
/* */
/* 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 */
@idkjs
idkjs / Seq.re
Last active June 24, 2021 10:20
Stdlib.Seq.re
/**************************************************************************/
/* */
/* 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 */
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
type ordering =
| Greater
| Less
| Equal;
// ORD typeclass / interface module
module type ORD = {
type t;
let compare: (t, t) => ordering;
};
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
)
@idkjs
idkjs / regexCheatsheet.re
Created June 16, 2021 15:28 — forked from sauvm/regexCheatsheet.re
regex cheatsheet
> 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.
@idkjs
idkjs / ObjectHasOwnProperty.re
Created June 16, 2021 15:14
Checks if Javascript Object has some property
// 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'));