Skip to content

Instantly share code, notes, and snippets.

module Control.Monad.Aff.AVar.Select
( Select
, put
, take
, select
) where
import Prelude
import Control.Monad.Aff (Aff)
module Grammar where
import Prelude
import Control.Applicative.Free (FreeAp, liftFreeAp, foldFreeAp)
import Control.Alt (class Alt, (<|>))
import Control.Alternative (class Alternative)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log, CONSOLE)
import Control.Plus (class Plus, empty)
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class
import Control.Monad.Aff (launchAff, Aff, makeAff, attempt)
import Control.Monad.Aff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (Error, try)
import Control.Monad.Except.Trans (ExceptT(..), runExceptT)
import Network.HTTP.Affjax as Ajax
module Main where
import Prelude
class Thunked a
instance thunkedAll :: Thunked a
type Thunk b = forall a. Thunked a => b
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Data.List (List(..), (:))
import Data.Maybe (Maybe(..))
import Halogen (ParentState, parentState, ParentQuery, Component, parentComponent, ParentHTML, Natural, ParentDSL, HalogenEffects, runUI)
import Halogen.HTML as H
import Halogen.Util (runHalogenAff, awaitBody)
import Unsafe.Coerce (unsafeCoerce)
@natefaubion
natefaubion / thread-result.js
Last active January 5, 2017 23:58
Sweet.js threading macro
arg |> foo[0].bar(42)
|> baz("hello", "there")
|> quux.foo().bar()
|> new Foo()
// Expands to:
// new Foo(quux.foo().bar(baz('hello', 'there', foo[0].bar(42, arg))));
arg |> foo() |> bar
// SyntaxError: [|>] Expected function call
// 31: arg |> foo() |> bar
macro constexpr {
rule { ($e:expr) } => {
(function() {
macro cexpr {
case { _ } => {
return [makeValue($e, #{ here })];
}
}
return cexpr;
}())
test = map ((*) 2) >>> filter ((>) 15) >>> drop 3 >>> map show
src1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
src2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
res1 = transduce' test src1 :: [String]
res2 = transduce' test src2 :: List String
module Control.Global (importLib) where
foreign import importLib
"function importLib(node) {\
\ return function(global) {\
\ if (typeof require !== 'undefined' && typeof process !== 'undefined') {\
\ return require(node);\
\ } else {\
\ return window[global];\
\ }\
macro protocol {
case { _ $name:ident { $fn:protocol_fn ... } } => {
// Probably not a good idea to rely on `__fresh`. Sweet.js should provide
// some sort of blessed gensym capability.
letstx $id = [makeValue(__fresh(), #{ here })];
return #{
function $name(proto, impl) {
if (!impl) {
impl = proto;
proto = {};