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 / MatchOn.elm
Created April 12, 2015 14:59
String Match On
matchOn : String -> String -> Maybe String
matchOn start string =
if startsWith start string
then
Just <| dropLeft (length start) string
else
Nothing
@TheSeamau5
TheSeamau5 / artistSearchExample.elm
Last active March 10, 2016 15:12
Artist Search Example
--------------------------
-- CORE LIBRARY IMPORTS --
--------------------------
import Json.Decode as Decode exposing (Decoder, object2, map, string, list, (:=))
import Task exposing (Task, andThen, succeed, fail, onError)
import Signal exposing (Signal, Mailbox, mailbox, message, send)
import String
-------------------------
@TheSeamau5
TheSeamau5 / digits.elm
Created April 22, 2015 03:07
Extract digits from a float
import String exposing (toList)
import Maybe
import List exposing (member)
import Graphics.Element exposing (show)
toChar x =
if | x == 0 -> '0'
| x == 1 -> '1'
| x == 2 -> '2'
| x == 3 -> '3'
@TheSeamau5
TheSeamau5 / pipeoperator.elm
Created April 22, 2015 11:54
Pipe operator in Elm
(->>) : a -> List (a -> a) -> a
(->>) x list = case list of
[] -> x
f :: fs -> (->>) (f x) fs
@TheSeamau5
TheSeamau5 / HackerNewsExample.elm
Last active September 23, 2018 00:24
Hacker news requests example
--------------------------
-- CORE LIBRARY IMPORTS --
--------------------------
import Task exposing (Task, ThreadID, andThen, sequence, succeed, spawn)
import Json.Decode exposing (Decoder, list, int, string, (:=), map, object2)
import Signal exposing (Signal, Mailbox, mailbox, send)
import List
---------------------------------
-- THIRD PARTY LIBRARY IMPORTS --
@TheSeamau5
TheSeamau5 / ParallelTask.elm
Created April 22, 2015 20:21
Run tasks in Parallel in Elm
parallel : Address a -> List (Task error a) -> Task error (List ThreadID)
parallel address tasks =
let
sendToAddress task = spawn (task `andThen` send address)
in
sequence (List.map sendToAddress tasks)
@TheSeamau5
TheSeamau5 / OptionalTasks.elm
Created April 22, 2015 20:28
Perform a sequence of optional tasks in Elm
optional : List (Task error value) -> Task error (List value)
optional list = case list of
[] -> succeed []
task :: tasks -> task
`andThen` (\value -> Task.map ((::) value) (optional tasks))
`onError` (\_ -> optional tasks)
@TheSeamau5
TheSeamau5 / killThread.js
Created April 26, 2015 02:27
Kill thread in Elm
/*
kill : ThreadID -> Task x ()
*/
function kill(id){
return asyncFunction(function(callback){
window.clearTimeout(id);
callback(succeed(Utils.Tuple0));
});
};
@TheSeamau5
TheSeamau5 / shrinking.elm
Last active August 29, 2015 14:20
Shrinking
property : String -> (a -> Bool) -> Arbitrary a -> Property
property name predicate arbitrary n seed =
let
-- failingTestCase' : Seed -> Int -> Trampoline (Result (a, Seed, Int) Int)
failingTestCase' seed accum =
if accum >= n
then
Done (Ok n)
else
let
module Lazy.List where
import Trampoline exposing (Trampoline(..), trampoline)
import Array exposing (Array)
import List
type LazyListView a
= Nil
| Cons a (LazyList a)