Skip to content

Instantly share code, notes, and snippets.

Avatar

Joël Quenneville JoelQ

  • Thoughtbot
  • Boston
View GitHub Profile
View elm-types-glossary.md

Elm Types Glossary

There's a lot of type terminology and jargon going around when discussing types in Elm. This glossary attempts to list some of the most common type terms along with synonyms, terms from other language communities, examples, and links to more detailed articles on each topic.

@JoelQ
JoelQ / RandomToTask.elm
Last active Sep 30, 2021
Turn an Elm random generator into task, allowing it to be chained with other side effects.
View RandomToTask.elm
-- 0.19
randomToTask : Generator a -> Task x a
randomToTask generator =
Time.now
|> Task.map (Tuple.first << Random.step generator << Random.initialSeed << Time.posixToMillis)
-- 0.18
@JoelQ
JoelQ / ellie_examples.md
Last active Jul 28, 2021
List of helpful Ellie's I've written
View ellie_examples.md
@JoelQ
JoelQ / math.rb
Last active Jun 30, 2021
Derive addition, multiplication, and exponentiation from from `Integer#next`
View math.rb
def add(number1, number2)
number2.times.reduce(number1) { |total| total.next }
end
add(2,3)
# => 5
def subtract(number1, number2)
number2.times.reduce(number1) { |total| total.pred }
end
@JoelQ
JoelQ / knuth_arrows.rb
Last active Jun 30, 2021
Exploration of Knuth Arrows as monoids
View knuth_arrows.rb
class Add
def self.mempty
new(0)
end
def initialize(number)
@number = number
end
attr_reader :number
@JoelQ
JoelQ / list-pattern-matching-elm.md
Last active Oct 29, 2020
What does `x :: xs` pattern matching mean in Elm?
View list-pattern-matching-elm.md

What does x :: xs pattern matching mean in Elm?

:: is the list prepend operator in Elm.

3 :: 2 :: 1 :: []

is equivalent to

@JoelQ
JoelQ / build-deploy
Created Mar 21, 2019
Netlify + Parcel deployment
View build-deploy
#!/bin/sh
set -e
echo "== BUILDING THE APP =="
yarn parcel build src/index.html
echo "== CONFIGURING REDIRECTS =="
if [ "$CONTEXT" = "production" ]; then
cp production_redirects dist/_redirects
@JoelQ
JoelQ / elm-generic-types-exercises.md
Last active May 26, 2020
Short exercises to learn how generic types and type variables work in Elm.
View elm-generic-types-exercises.md

Generic Elm types exercises

A series of exercises to get a feel for how generic types and type variables work in Elm. For each of these, you are given some code that is not compiling. Your task is to get it compiling. You can change the body of the function but not the signature. No cheating with Debug.todo or infinite recursions either 😉

@JoelQ
JoelQ / Ball.elm
Last active Oct 23, 2019
Gravity and Ball
View Ball.elm
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Color exposing (..)
import Keyboard
import Time
import Debug
-- Model
type alias Model = { x : Float, y : Float, radius: Float }
@JoelQ
JoelQ / conditionals_to_booleans_ruby.md
Created Dec 5, 2018
Common Ruby conditionals refactored to boolean expressions
View conditionals_to_booleans_ruby.md

Redundant if/else - identity

def can_edit?
  if admin?
    true
  else
    false
  end
end