Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
@TheSeamau5
TheSeamau5 / selection-list.js
Created April 19, 2016 18:06
Selection List in Javascript using Immutable
import Immutable from 'immutable';
/* Selection List Data Structure */
class SelectionList {
constructor(list) {
if (list.length > 0) {
this._previous = new Immutable.Stack();
this._selected = list[0];
this._next = new Immutable.Stack(list.splice(1));
/*
* type Definition = {
* kind: String,
* name: String,
* properties: [Property]
* }
*
* type Property = {
* key: String,
* value: [String]
import Html exposing (Html)
import Signal exposing (Address)
type alias Init options state effect
= options -> (state, List effect)
type alias Update action state effect
= action -> state -> (state, List effect)
type alias View action state
type alias Transition state effect = (state, List effect)
pipe : List a -> (a -> state -> Transition state effect) -> state -> Transition state effect
pipe actions update state =
case actions of
[] ->
(state, [])
x :: xs ->
import Html exposing (Html, Attribute, ul, li, div)
import Html.Attributes
import Html.Events exposing (on)
import Json.Decode exposing (Decoder, (:=), at, float)
import List
import Signal exposing (Address, message)
import Array exposing (Array)
----------------------------------------------------------
type Automaton a b = Automaton (a -> (b, Automaton a b))
arr : (a -> b) -> Automaton a b
arr f =
Automaton (\a -> (f a, arr f))
(>>>) : Automaton a b -> Automaton b c -> Automaton a c
(>>>) (Automaton f) (Automaton g) =
Automaton <|
\a ->
type Process a b
= Put b (Process a b)
| Get (a -> Process a b)
put : b -> Process a b -> Process a b
put =
Put
get : (a -> Process a b) -> Process a b
type alias Parser s a b =
{ static : StaticParser s
, dynamic : DynamicParser s a b
}
type alias StaticParser s =
{ flag : Bool
, startingChars : List s
}
type alias Continuation a r = (a -> r) -> r
andThen : Continuation a r -> (a -> Continuation b r) -> Continuation b r
andThen cont f br =
cont (flip f br)
constant : a -> Continuation a r
constant a f = f a
powerset : List a -> List (List a)
powerset =
List.foldr (\x acc -> acc ++ List.map ((::) x) acc) [[]]