Skip to content

Instantly share code, notes, and snippets.

View mlms13's full-sized avatar
⚗️

Michael Martin mlms13

⚗️
View GitHub Profile
@mlms13
mlms13 / CommonInfix.re
Last active December 5, 2019 10:07
Commonly-used infix functions in functional programming (Reason edition)
let (<|) = ('a => 'b, 'a) => 'b; // purescript and haskell use ($)
let (|>) = ('a, 'a => 'b) => 'b; // purescript uses (#)
let compose: ('b => 'c, 'a => 'b, 'a) => 'c;
let (<<) = compose; // purescript uses (<<<), haskell uses (.)
let composeFlipped: ('a => 'b, 'b => 'c, 'a) => 'c;
let (>>) = composeFlipped; // purescript uses (>>>)
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
@mlms13
mlms13 / Overlapping.re
Created April 9, 2019 16:09
Different approaches to representing elements pulled out from the natural flow (menus, tooltips, etc)
let onClick = _ => send(ToggleMenu);
// The following is how elm-ui does it (translated to JSX)
// Pros:
// - Relatively easy to understand
// - `Button` is any normal component
// - It's obvious that the container element can have all of the normal
// layout props and decoration attributes
//
// Cons:
@mlms13
mlms13 / DoFuture.re
Created April 9, 2019 00:08
I don't know anything about PPXs, and I'm not even quite a do-notation pro, but I'd really like something like this in Reason
[%do Future]
do {
user <- getUser("some_user_id")
orders = user.orders
firstOrderId <- orders |> List.head |> Future.fromOption
order <- getOrder(firstOrderId)
pure(user.firstName ++ " ordered a " ++ order.productName)
};
Future.(
@mlms13
mlms13 / BooleanRuleEngine.re
Created March 28, 2019 23:35
Evaluate rules using other rules?
// I'm not entirely sure what this thing is. It feels powerful and expressive
// and like you can compose things. Not sure what it would be useful for, though.
// Maybe you could make a UI to build arbitrarily complex predicate functions
// for filtering collections of data?
module RuleEngine = {
type t('a) =
| Rule('a)
| Not(t('a))
| And(t('a), t('a))
[@bs.module "react-native-calendario"]
external calendar: ReasonReact.reactClass = "default";
type dateRange = {
startDate: Js.Date.t,
endDate: option(Js.Date.t),
};
let dateRangeFromJS = range => {
startDate: range##startDate,

Current behavior

onfocus: send UpdateLocationSuggesion

UpdateLocationSuggesion

  • if we already have geolocation: send UpdateLocationSuggesions
  • if we don't: send GetLocation

UpdateLocationSuggesions

  • if mobile and empty input and LocationSuccess:
@mlms13
mlms13 / TFirstTLast.re
Created February 24, 2019 18:01
t-first and t-last approach when working with nested data structures in Reason
/**
* t-first and t-last examples when working with `Future.t(Result.t('a, 'e))`
**/
// `Future` and `Result` are both t-last
getJSON("some/url")
|> Future.map(Result.flatMap(decodeUser))
|> Future.map(Result.mapWithDefault(DataFailed, v => ShowData(v)))
|> Future.tap(send);
@mlms13
mlms13 / elm-game-loop.md
Created February 21, 2019 22:21
Like TEA, but for a game loop?

The Elm Architecture, specialized for games.

Key points:

  • Instead of reacting to events, application state is updated on regular intervals
    • The engine collects all input events (keys up/down, mouse movement, button clicks, possibly joysticks, game pads)
    • User of this library specifies how to translate diffs in input events to game actions
  • Instead of a single "update" function, there are several specialized functions
    • physics update
  • given a current state (which should include things like position and velocity) and a time delta, provide a new state
@mlms13
mlms13 / ChangelogBuilder.re
Last active February 15, 2019 23:34
Categorize Git Commits
module Git = {
type commitish = Sha(string);
type commit = {
title: string,
descriptiong: string,
author: string,
date: Date.t
};