Skip to content

Instantly share code, notes, and snippets.

@adauguet
adauguet / Result.Extra.elm
Last active Nov 10, 2020
A function to handle a list of Result x a
View Result.Extra.elm
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 Mar 6, 2019
French phone number validation
View FrenchPhoneNumber.elm
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/
View UIColor+Hex.swift
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