Skip to content

Instantly share code, notes, and snippets.

@JBetz
JBetz / dyn_over_either.hs
Last active Jan 28, 2019
dynamic that only updates when constructor changes
View dyn_over_either.hs
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 Jan 19, 2019
type list iteration example
View Generate.hs
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
View gist:d900b9fd6457f4c9c26b8a0c83084d08
backend :: Backend BackendRoute FrontendRoute
backend = Backend
{ _backend_run = \_ -> do
app <- mkApp
Warp.run 3000 app
, _backend_routeEncoder = backendRouteEncoder
}
View MenuedWidget.hs
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 Oct 9, 2018
constrained type won't unify
View Filter.purs
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)
View gist:c0ad3a8fa54ee00ccf94218215feb657
{}:
(import ./.obelisk/impl {}).project ./. ({ pkgs, ... }:
{
packages = {
servant-reflex = pkgs.fetchFromGitHub {
owner = "imalsogreg";
repo = "servant-reflex";
rev = "ec8723351c8245f29a88cc5e6250533d2d6f4761";
sha256 = "1r8z95hpl6f5pql1f6a3plczahym09fdnxkcg3a6ildw6chmips0";
};