Skip to content

Instantly share code, notes, and snippets.

View Warry's full-sized avatar

Maxime Dantec Warry

View GitHub Profile
@Warry
Warry / propMap.elm
Last active November 19, 2019 04:15
Convert a List of objects into a Dict (≈ Map) using an object's property as key, in a type safe way with ELM
import Dict
-- The transformation function
listToDict : (a -> comparable) -> [a] -> Dict.Dict comparable a
listToDict getKey values = Dict.fromList (map (\v -> (getKey v, v)) values)
-- Demo type
type FooBar =
{ foo : String
, bar : Int
module Test where
import Text (asText)
import Array (Array, get)
import Json.Decode (..)
import Maybe (..)
type alias Foo =
{ foo : String
, bar : Bar
@Warry
Warry / pipe.md
Last active August 9, 2016 15:50
Why do you use `(flip andThen)`?

Why do you use (flip andThen)?

TLDR; To use it with the pipe (|>) operator.

The actual andThen problem

Here is the signature for Task.andThen:

import Task exposing (andThen)
@Warry
Warry / MagicJson.elm
Last active May 31, 2019 12:39
unsafe elm json encoder+decoder
module MagicJson exposing (encode, decode, decoder)
import Json.Encode as Encode exposing (Value)
import Json.Decode as Decode exposing (Decoder)
import Http
encode : a -> Value
encode jsonEncodeElmValue =
@Warry
Warry / jum-1.svg
Last active September 13, 2019 19:45
Just use monads
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.