Skip to content

Instantly share code, notes, and snippets.

View ThomasCrevoisier's full-sized avatar

Thomas Crevoisier ThomasCrevoisier

View GitHub Profile
@ThomasCrevoisier
ThomasCrevoisier / gist:2ca1476b197bbf5de9ce
Last active August 29, 2015 14:15
purescript-sample
module Exercises where
import Math
import Control.Monad.Eff.Random
import Control.Monad.Eff
import Control.Monad.ST
import Debug.Trace
combineMaybe :: forall a f. (Applicative f) => Maybe (f a) -> f (Maybe a)
combineMaybe (Just x) = pure <$> x
combineMaybe Nothing = pure Nothing
module Exercises where
import Data.Monoid
class (Monoid m) <= Action m a where
act :: m -> a -> a
instance repeatAction :: Action Number String where
act 0 _ = ""
act n s = s ++ act (n - 1) s
@ThomasCrevoisier
ThomasCrevoisier / monetjs_example#1
Created December 23, 2014 23:14
A simple example using Maybe monad of MonetJS
// Run the code with NodeJS
var Monet = require('monet');
function getValue (obj, keysString) {
var keys = keysString.split('.');
var curr = obj;
keys.forEach(function (key) {
@ThomasCrevoisier
ThomasCrevoisier / ClojureScript_example#1
Last active August 29, 2015 14:11
Keyword to property conversion in ClojureScript
;;; ClojureScript example from David Nolen's talk "ClojureScript : Lisp's revenge"
;;; https://www.youtube.com/watch?v=MTawgp3SKy8
(defn capitalize [s]
(str (.toUpperCase (aget s 0))
(.substring s 1)))
(defn keyword->property [k]
(let [[x & xs] (-> (str k) (.substring 1) (.split "-"))]
(apply str x (map capitalize xs))))
@ThomasCrevoisier
ThomasCrevoisier / ClojureScript_example
Created December 17, 2014 21:59
Simple example of ClojureScript
(ns poney.world)
(defn hastalavistaify [xs]
(str "Hasta la vista " xs))
(hastalavistaify "Thomas") ;;; Outputs : "Hasta la vista Thomas"
(map hastalavistaify ["Thomas" "poney" "mutability"]) ;;; Outputs : ("Hasta la vista Thomas" "Hasta la vista poney" "Hasta la vista mutability")