Skip to content

Instantly share code, notes, and snippets.

View rupertlssmith's full-sized avatar

Rupert Smith rupertlssmith

  • The Sett Ltd.
  • Edinburgh, Scotland.
View GitHub Profile
@rupertlssmith
rupertlssmith / StateModel.elm
Last active January 11, 2018 16:19
Experimenting with state machines in Elm
module StateModel
exposing
( boolToMaybe
, (>&&>)
, (>||>)
, defaultTransition
, mapWhenCompose
)
import Maybe exposing (andThen)
@rupertlssmith
rupertlssmith / Channels.elm
Last active January 16, 2018 11:48
Experimenting with typed channels in Elm
module Channels exposing (..)
import Html exposing (Html)
import Time exposing (Time, every, second)
-- Example
type alias Model =
@rupertlssmith
rupertlssmith / ProgramCombinator.elm
Created January 19, 2018 15:13
Program Combinator
module ProgramCombinator exposing (..)
import Html exposing (Html)
import Time exposing (Time, every, second)
-- Example
type alias Model =
@rupertlssmith
rupertlssmith / Tree.elm
Last active July 2, 2018 11:12
The 'tea-tree' data structure is a rose-tree implementation with some additional features that help when working with the Elm update cycle.
module Tree
exposing
( Tree
, Zipper
, Path
-- Tree operations
, singleton
, zipper
, map
-- Zipper operations
@rupertlssmith
rupertlssmith / BasicSyntax.elm
Last active December 4, 2018 21:16
Elm Syntax
module BasicSyntax exposing (..)
fact : Int -> Int
fact n =
if n == 0 then
1
else
n * fact (n - 1)
map : (a -> b) -> List a -> List b
@rupertlssmith
rupertlssmith / AsCustomType.elm
Last active October 30, 2019 16:20
Elm Enums
-- This way gives you a custom type, which can be used to branch on in code with case of.
type Pet
= Cat
| Dog
| Snake
| Spider
petEnum =
@rupertlssmith
rupertlssmith / Traits.elm
Created June 12, 2018 10:36
Traits in Elm
module Traits exposing (..)
type GameState
= State
{-| FireTrait defines how the game state is updated for any kind of shooting
event.
's' is the state implementation parameter,
@rupertlssmith
rupertlssmith / LocalStoragePort.elm
Last active January 31, 2022 15:41
Local storage using Elm port.
port module Ports.LocalStoragePort exposing (clear, getItem, listKeys, response, setItem)
import LocalStorage exposing (ClearPort, GetItemPort, ListKeysPort, ResponsePort, SetItemPort)
port getItem : GetItemPort msg
port setItem : SetItemPort msg
module Sticky.Editor exposing
( Model, Msg, init, update, view
, Style(..), BlockStyle(..)
, toggleStyle, toggleBlockStyle
, ControlContext, getControlContext
, Selection(..)
, setSelection
)
{-|
module Main exposing (main)
import Browser
import Html exposing (Html)
import Html.Events
import Json.Decode
import Json.Encode
type alias Flags =