Skip to content

Instantly share code, notes, and snippets.

/*
Copyright 2015 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
{
"recipient":"[email protected]",
"evidence":"http://google.com",
"issued_on":"2012-05-21",
"badge":{
"version":"1.0.0",
"name":"Explorer",
"image":"http://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Smiley.svg/2000px-Smiley.svg.png",
"description":"Has displayed expertise in hand-made badge creation.",
"criteria":"http://etec.hawaii.edu",
[{
"identity":{
"originator_id":"a9a860ae-7c0f-4c12-a1cf-9fe490ee1f49",
"id":"poly-sci-101"
},
"original":{
"timestamp":"2015-01-02T22:17:00.371Z",
"uri":"http://study.com/academy/course/political-science-course.html",
"share":true,
"propagate":true,
[{
"identity":{
"originator_id":"a9a860ae-7c0f-4c12-a1cf-9fe490ee1f49",
"id":"local-lti-provider"
},
"original":{
"timestamp":"2015-01-02T22:17:00.371Z",
"uri":"http://lti-provider.paulgray.net",
"share":true,
@pfgray
pfgray / wat.js
Created September 16, 2016 03:47
const INVALID = 'INVALID';
const VALID = 'VALID';
const Invalid = reasons => ({
type: INVALID,
reasons: reasons,
and: and,
bifold: bifold
});
import java.util.function.Supplier
import scalaj.http.Http
import scala.concurrent.blocking
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scalaz.concurrent.Task
object AsyncTest {
/**
* ADT
*/
sealed trait MultipleOrOne[A] {
def exists(f: A => Boolean) =
this match {
case Multiple(all) => all.exists(f)
case One(one) => f(one)
}
}
@pfgray
pfgray / Do.js
Created August 2, 2018 05:05
Do syntax for js
// nested chaining is a common occurence for monads:
// type Maybe = Just(a) | Nothing
Just(5)
.chain(num => Just(num * 2)
.chain(num2 => Just(num2 + 3)
.map(num3 => ({num, num2, num3}))
)
alert("Testing")
@pfgray
pfgray / Do.js
Last active September 16, 2018 20:34
// Do works with any Monad that implements the fantasy-land spec
// https://github.com/fantasyland/fantasy-land#monad
function Do(Type) { return (a, ...fns) => {
function doIt(as, fns) {
const [fn, ...rest] = fns;
if(rest.length === 0) {
return as['fantasy-land/chain'](a2s => {
return Type['fantasy-land/of'](fn.apply(null, a2s));
});
} else {