This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SingletonIncrementer exposing (..) | |
import Platform exposing (Task(..)) | |
import Task | |
cast : | |
(a -> msg) | |
-> (a -> state -> state) | |
-> Task Never () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GlobalCounter exposing (..) | |
type alias Model = Int | |
type Msg | |
= Increment | |
| Decrement | |
| Reset | |
| GetState Pid | |
main = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "Sum of lists" do | |
assert Hello.sum([]) == 0 | |
assert Hello.sum([2]) == 2 | |
assert Hello.sum([1, 2, 3, -1, -2, -3]) == 0 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule FizzBuzz do | |
use Elmchemy | |
import XList, only: [{:'range', 0},{:'map', 0}] | |
@doc """ | |
Fizzes the buzzes and buzzfizzes the fizz out of buzz | |
iex> import FizzBuzz | |
iex> fizzbuzz.(1).(7) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FizzBuzz exposing (fizzbuzz) | |
import List exposing (map, range) | |
{-| Fizzes the buzzes and buzzfizzes the fizz out of buzz | |
fizzbuzz 1 7 == "1 2 Fizz 4 Buzz Fizz 7" | |
-} | |
fizzbuzz : Int -> Int -> String | |
fizzbuzz from to = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def example do | |
item = {10, 2, {20, 30, []}} | |
case item do | |
{10, 2, {20, 30}, []} -> :ok | |
end | |
end | |
example() | |
## -> ** (CaseClauseError) no case clause matching: {10, 2, {20, 30, []}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -*- mode: emacs-lisp -*- | |
;; This file is loaded by Spacemacs at startup. | |
;; It must be stored in your home directory. | |
(defun dotspacemacs/layers () | |
"Configuration Layers declaration. | |
You should not put any user code in this function besides modifying the variable | |
values." | |
(setq-default | |
;; Base distribution to use. This is a layer contained in the directory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[action.type, matchedKey, "_"].reduce( (acc, a) => | |
acc || handlers.hasOwnProperty(a) && handlers[a](state, action) | |
, null) || state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GameOfLife where | |
import [Enum, Access] | |
neighbours(x,y, state) -> | |
[{nx, ny} || nx <- -1..1, ny <- -1..1] | |
|> reduce(0, ({nx, ny}, acc) -> (state[x + nx][y + ny] || 0) + acc) | |
alive(1, n) -> if n in 2..3, do: 1, else: 0 | |
alive(0, n) -> if n == 3, do: 1, else: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@spec chunk(t, pos_integer, pos_integer, t | nil) :: [list] | |
def chunk(enumerable, count, step, leftover \\ nil) | |
when is_integer(count) and count > 0 and is_integer(step) and step > 0 do | |
limit = :erlang.max(count, step) | |
{acc, {buffer, i}} = | |
reduce(enumerable, {[], {[], 0}}, R.chunk(count, step, limit)) | |
if is_nil(leftover) || i == 0 do | |
:lists.reverse(acc) |