This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE Rank2Types #-} | |
{-# LANGUAGE TypeSynonymInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE RecordWildCards #-} | |
module Control.Lens.Foci where | |
import qualified Control.Category as Cat | |
import Control.Applicative | |
import Control.Monad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial, wraps, reduce | |
class Fold: | |
def __init__(self, zero, update, out): | |
self.zero = zero | |
self.update = update | |
self.out = out | |
def __add__(self, other): | |
zero = (self.zero, other.zero) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s3AccessKey :: EnvVar Aws.AccessKey | |
s3AccessKey = mkEnvVar "S3_ACCESS_KEY" (Just . Aws.AccessKey . convertString) Nothing | |
s3SecretKey :: EnvVar Aws.SecretKey | |
s3SecretKey = mkEnvVar "S3_SECRET_KEY" (Just . Aws.SecretKey . convertString) Nothing | |
s3FromKeys :: EnvVar Aws.Credentials | |
s3FromKeys = iI Aws.FromKeys s3AccessKey s3SecretKey Ii |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.typesafe.config.{Config, ConfigFactory} | |
object Configured extends App { | |
val config = ConfigFactory.load() | |
import TypesafeConfig._ | |
import FreeConfig._ | |
import scalaz.syntax.apply._ | |
val kafkaProducerBackoff: BackoffConfig[KafkaProducerBackoff] = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Control.Foldl as Fold | |
import Control.Applicative | |
import Data.Profunctor | |
type Price = Double | |
type Prices = [ Price ] | |
type Period = Int | |
changes :: Prices -> Prices | |
changes ps = zipWith (-) (tail ps) ps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Scanl | |
import Pipes | |
import Pipes.Lift | |
scanMToPipe :: (Monad m) => ScanM m a b -> Pipe a b m () | |
scanMToPipe (ScanM step initial) = | |
let pipe = do | |
a <- await | |
b <- lift $ step a | |
yield b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ: let a = stagger [] (arr (1:)) (arr (0:)) in mapM_ print $ scan a (Prelude.replicate 5 ()) | |
([1],[0,1]) | |
([1,0,1],[0,1,0,1]) | |
([1,0,1,0,1],[0,1,0,1,0,1]) | |
([1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1]) | |
([1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0,1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Dynamic where | |
Dynamic :: Typeable t => t -> Dynamic | |
elimDynamic :: (forall a. Typeable a => a -> r) -> Dynamic -> r | |
elimDynamic f (Dynamic a) = f a | |
fromDynamic :: Typeable a => Dynamic -> Maybe a | |
fromDynamic = elimDynamic cast | |
liftD2 :: forall a b r. ( Typeable a , Typeable b , Typeable r ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package utils | |
import org.apache.beam.sdk.options.ValueProvider | |
import org.apache.beam.sdk.options.ValueProvider.{ | |
NestedValueProvider, | |
StaticValueProvider | |
} | |
import scalaz.{Applicative, Functor} | |
object ValueProviderPimp { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object CoGroupByKeyUtil { | |
// a workaround for scala's lack of rank-2 polymorphism | |
// so that we can allow the called function to decide how to instantiate F[_] | |
trait Rank2[F[_]] { | |
def apply[A]: F[A] | |
} | |
def eitherOf[K: Coder, A: Coder, B: Coder]( | |
left: PCollection[KV[K, A]], | |
right: PCollection[KV[K, B]], |
OlderNewer