Skip to content

Instantly share code, notes, and snippets.

@JBetz
JBetz / dyn_over_either.hs
Last active January 28, 2019 15:17
dynamic that only updates when constructor changes
renderEither :: Dynamic t (Either a b) -> m ()
renderEither eitherD = do
uniqEitherD <- holdUniqDynBy (\x y -> isRight x && isRight y || isLeft x && isLeft y) eitherD
dyn_ $ ffor uniqEitherD $ \case
Left val -> renderLeft $ fromLeft val <$> eitherD
Right val -> renderRight $ fromRight val <$> eitherD
renderLeft :: Dynamic t a -> m ()
renderRight :: Dynamic t b -> m ()
@JBetz
JBetz / Generate.hs
Last active January 19, 2019 17:17
type list iteration example
generate :: [e] -> [Structure e]
generate objs =
let (otStrs, objs2) = generateFrom @OT objs
(ttStrs, objs3) = generateFrom @TT objs2
(btStrs, objs4) = generateFrom @BT objs3
(lStrs, _) = generateFrom @L objs4
in otStrs ++ ttStrs ++ btStrs ++ lStrs
-- first element of the tuple is all the structures that could be generated from the given list of objects
-- second element is all the objects that remain, i.e., that weren't used to generate one of the structures
backend :: Backend BackendRoute FrontendRoute
backend = Backend
{ _backend_run = \_ -> do
app <- mkApp
Warp.run 3000 app
, _backend_routeEncoder = backendRouteEncoder
}
class MonadWidget t m => MonadDiamondWidget t m where
getGlobalKeydownEvent :: m (Event t Key)
getGlobalKeyupEvent :: m (Event t Key)
getKeyLayout :: m (Dynamic t KeyLayout)
menuedWidget
:: forall t m a b
. MonadDiamondWidget t m
=> (Event t a -> m b)
-> Menu a
@JBetz
JBetz / Filter.purs
Last active October 9, 2018 14:26
constrained type won't unify
type ProjectColumnFilter =
{ prop :: forall label a r'. IsSymbol label => Show a => Cons label a r' Types.ProjectRow => SProxy label
, propFilter :: PropertyFilter
}
filterProjects :: Pattern -> Array ProjectColumnFilter -> Array Types.Project -> Array Types.Project
filterProjects pattern columnFilters projects =
Array.filter (\proj -> matchesPattern proj && matchesFilters proj) projects
where
matches pat val = contains pat (toLower val)
{}:
(import ./.obelisk/impl {}).project ./. ({ pkgs, ... }:
{
packages = {
servant-reflex = pkgs.fetchFromGitHub {
owner = "imalsogreg";
repo = "servant-reflex";
rev = "ec8723351c8245f29a88cc5e6250533d2d6f4761";
sha256 = "1r8z95hpl6f5pql1f6a3plczahym09fdnxkcg3a6ildw6chmips0";
};