Skip to content

Instantly share code, notes, and snippets.

View akhileshs's full-sized avatar

Akhilesh Srikanth akhileshs

  • San Francisco, CA
View GitHub Profile
scala> "{ /* hello */ def foo(bar: Int) = bar }".parse[Term].get
res0: scala.meta.Term = { /* hello */ def foo(bar: Int) = bar }
scala> res0 transform { case q"bar" => q"baz" }
x.origin: Parsed(Input.String("{ /* hello */ def foo(bar: Int) = bar }"),Scala211,[18..21) in Input.String("{ /* hello */ def foo(bar: Int) = bar }"))
x : foo
x.origin: Transformed(bar)
x : baz
class Contravariant f where
fmap :: (b -> a) -> f a -> f b
newtype Predicate a = Predicate { runPredicate :: a -> Bool }
instance Contravariant Predicate where
fmap f (Predicate a) = Predicate (a . f)
data MyOrdering = LT | EQ | GT
import Control.Monad
class Profunctor p where
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d
-- lmap :: (a -> b) -> p b c -> p a c
-- rmap :: (c -> d) -> p b c -> p b d
instance Profunctor (->) where
-- dimap :: (a -> b) -> (c -> d) -> (->) b c -> (->) a d
@ def id[A](x: A): A = x
defined function id
@ def k[A, B](x: A, y: B): A = x
defined function k
@ def a[A, B](f: A => B, x: A): B = f(x)
defined function a
@ a((x: Int) => x + 1, 1)