Skip to content

Instantly share code, notes, and snippets.

@paulvictor
paulvictor / retry.purs
Created March 21, 2017 10:11
Retrying in purescript
retry' :: ∀ e a. Eff e a → (a → Boolean) → Int → String → ExceptionableEff e a
retry' action cond i errMsg = ExceptT $ retry'' action cond i errMsg
where retry'' action cond i errMsg | i <= 0 = map (\_ → Left errMsg) action
| otherwise = do
res ← action
if cond res then pure $ Right res else retry'' action cond (i-1) errMsg
@paulvictor
paulvictor / retryAff.purs
Created March 21, 2017 10:59
Retrying an Aff
module Main where
import Control.Monad.Aff
import Control.Monad.Eff.Console
import Control.Monad.Eff
import Network.HTTP.Affjax
import Network.HTTP.StatusCode
import Data.Functor
import Network.HTTP.Affjax.Response
import Control.Monad
@paulvictor
paulvictor / ForeignObjectHelper.purs
Created April 7, 2017 11:41
Getting data from JS objects
module Object where
import Prelude
import Data.Foreign
import Data.Foreign.Class
import Data.String
import Data.List (List(..), fromFoldable)
import Data.List.Types
import Data.Either
import Control.Monad.Except.Trans
@paulvictor
paulvictor / config
Created June 7, 2017 09:40
i3-config
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFlvASQBCADeRkGri0A+UEOlER16ev8wDZ2+kHPxk4y63vjNCLf1AYE5Dcnl
YiBA6FHr4cf66ECg83PqtOZiCRw3T75jX3MYcwKOtWghrlIjsRZBNk6gSvm7DbbT
0RsVw9HPb/EhxsVQoiDb7SIeTNOoWjr20ixdUW4WRy+OCRNxuxzM65B8SrJKftEz
UKIxMo6JqRzEqDALsJB+8FmY1ZqsmWiI/5LSp131obm6dS653fawGpxHw4AKna5U
scsT7LmcFrv18ID1ca/e2XXnBGogtEg23I2Tv2svOtJld3Q69aBbW1bidi7q/+DS
fzlXsdKtlv3iHTRpxHOP+jlbJ1kSKcUbFl5HABEBAAG0PlBhdWwgVmljdG9yIFJh
aiAoUGF1bCBWaWN0b3IncyBHUEcga2V5KSA8cGF1bHZpY3RvckBnbWFpbC5jb20+
iQFOBBMBCAA4FiEEP8i/n4ahkxxtV8peRuauRp9+Y+oFAllvASQCGwMFCwkIBwIG
0x0ea94785c4a59Db46e02129ddfaD9962F29011Eb
@paulvictor
paulvictor / RandomBehavior.js
Created February 20, 2018 23:52
Random Integers as a behavior
exports.affToEvent = function(aff) {
return function(sub) {
aff(function(a) { sub(a); }, function(e){})
}
}
exports.randomIntBetween = function(min) {
return function(max) {
return function(e) {
return function(sub) {
@paulvictor
paulvictor / RecordMod.purs
Created March 6, 2018 06:26
FillInNestedRecords
module RecordMods where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Foreign (Foreign)
import Data.Record (insert)
import Data.Symbol (SProxy(..))
newtype Person = Person {firstName :: String, lastName :: String, address :: Address}
class RowSubset (row :: # Type) (xs :: RowList) (subrow :: # Type) | xs -> subrow where
subsetImpl :: RLProxy xs -> {|row} -> {|subrow}
instance nilRowSubset :: RowSubset row Nil () where subsetImpl _ _ = {}
instance consRowSubset
::
( IsSymbol sym
, Cons sym a subrowWithoutSym subrowWithSym
, Cons sym a srcWithoutSym src
@paulvictor
paulvictor / TypeLevelFoo.purs
Last active July 30, 2018 12:25
Decode for a value which has a type level default
newtype WithDefault b a = WithDefault a
instance showWithDefault :: Show a => Show (WithDefault b a) where
show (WithDefault a) = show a
class Reflect a b | b -> a where
reflect :: Proxy a -> b
instance reflectSProxyString :: IsSymbol sym => Reflect (SProxy sym) String where
reflect = const (reflectSymbol (SProxy :: SProxy sym))