Skip to content

Instantly share code, notes, and snippets.

@nsaunders
nsaunders / Apply.purs
Created July 13, 2023 03:24
applyRecord in PureScript
module Record.Apply where
import Prelude
import Data.Symbol (class IsSymbol)
import Prim.Row as Row
import Prim.RowList (class RowToList, RowList)
import Prim.RowList as RL
import Record as Record
import Record.Builder as RB
@nsaunders
nsaunders / Keys.purs
Created August 27, 2019 14:32
Keys (labels) from a row in PureScript
module Keys where
import Prelude (Unit, mempty, ($))
import Data.List.Types (List, (:))
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
import Effect (Effect)
import Effect.Console (logShow)
import Type.Data.Row (RProxy(..))
import Type.RowList (class RowToList, Cons, Nil, RLProxy(..), kind RowList)
@nsaunders
nsaunders / App.purs
Last active January 30, 2019 21:01
A simple Halogen form abstraction leveraging the Reader monad and lenses
module App (Query, app) where
import Prelude
import Control.Monad.Reader (Reader, asks, runReader)
import Data.Array ((:))
import Data.Lens (Lens', (^.), _1, _2, set, view)
import Data.Lens.Record (prop)
import Data.Maybe (Maybe(Nothing))
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..))
@nsaunders
nsaunders / App.purs
Last active January 30, 2019 19:21
A Halogen "component" roughly analogous to a stateless React component
{-
This example shows how to create the Halogen equivalent of a stateless React component.
Notice that "incrementer" is not a Halogen Component at all; rather, it is merely a function that produces a view using
Halogen's HTML DSL.
-}
module App (Query, app) where
@nsaunders
nsaunders / Main.hs
Created July 3, 2018 23:40
lookupEnv / MaybeT
module Main where
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
import Data.Maybe (Maybe(..), fromMaybe)
import System.Environment (lookupEnv)
data ConnectInfo = ConnectInfo { host :: String, user :: String, pass :: String }
deriving Show
@nsaunders
nsaunders / Main.purs
Created May 18, 2018 21:55
PureScript + Hyper + Mongo - basic auth
module Main where
import Prelude
import Control.IxMonad ((:>>=), (:*>))
import Control.Monad.Aff (Aff, attempt)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Data.Argonaut (class DecodeJson, (.?), decodeJson)
import Data.Either (hush)
import Data.Maybe (Maybe)