Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@adauguet
adauguet / Result.Extra.elm
Last active November 10, 2020 21:36
A function to handle a list of Result x a
partition : List (Result x a) -> ( List x, List a )
partition results =
let
helper : List (Result x a) -> ( List x, List a ) -> ( List x, List a )
helper list ( es, ss ) =
case list of
[] ->
( es, ss )
x :: xs ->
@adauguet
adauguet / FrenchPhoneNumber.elm
Last active March 6, 2019 16:20
French phone number validation
module Phone exposing (phoneParser)
import Parser exposing ((|.), (|=), Parser, Step(..), andThen, chompWhile, end, getChompedString, loop, oneOf, problem, run, succeed, symbol)
-- French phone number validation
-- This code makes sure that the phone number has one of the following prefixes: 0033 | +33 | 0.
-- This is only used for validation purposes so the prefix is not retained.
-- source https://korban.net/posts/elm/2018-09-07-introduction-elm-parser/
import UIKit
extension Int {
init?(hexString: String) {
let string = hexString.replacingOccurrences(of: "#", with: "")
self.init(string, radix: 16)
}
var rgb: (red: Int, green: Int, blue: Int) {
let red = self >> 16 & 0xff