::
is the list prepend operator in Elm.
3 :: 2 :: 1 :: []
is equivalent to
class Tree | |
attr_reader :value, :left, :right | |
def initialize(value, left, right) | |
@value = value | |
@left = left | |
@right = right | |
end | |
def reduce(initial, &block) |
::
is the list prepend operator in Elm.
3 :: 2 :: 1 :: []
is equivalent to
-- 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 |
I often write Ellies to demo an idea or to share a solution with someone on Slack. Some of them are helpful enough to share many times so I keep a reference to them here. Others are just cool so I want to save the link 😎
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 |
class Add | |
def self.mempty | |
new(0) | |
end | |
def initialize(number) | |
@number = number | |
end | |
attr_reader :number |
#!/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 |
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 } |
Redundant if/else - identity
def can_edit?
if admin?
true
else
false
end
end
puts "4 line REPL (read eval print loop)" | |
$stdin.each_line do |line| # READ | |
return_value = eval(line.chomp) # EVAL | |
puts return_value # PRINT | |
end # LOOP |