Skip to content

Instantly share code, notes, and snippets.

@typeclass trait NonEmptyTraverseUnordered[F[_]] {
def nonEmptyTraverseUnordered[G[_]: CommutativeApply, A, B](sa: F[A])(f: A => G[B]): G[F[B]]
def nonEmptySequenceUnordered[G[_]: CommutativeApply, A](fga: F[G[A]]): G[F[A]] =
nonEmptyTraverseUnordered(fga)(identity)
}
@typeclass trait NonEmptyCommutativeParallel[F[_], M[_]] {
def commutativeApply: CommutativeApply[F]
def commutativeFlatMap: CommutativeFlatMap[M]
package cats.free
import cats.free.Free.{FlatMapped, Pure, Suspend}
import cats.{Applicative, Monad, Parallel, ~>}
import cats.implicits._
class FreeParallel[S[_], A](val value: Free[FreeApplicative[S, ?], A]) extends AnyVal
object FreeParallel {
def apply[S[_], A](fp: Free[FreeApplicative[S, ? ], A]): FreeParallel[S, A] = new FreeParallel(fp)
@LukaJCB
LukaJCB / Main.scala
Created September 10, 2017 15:09
ParallelTaglessFinal
import cats._
import cats.implicits._
trait Alg[M[_]] {
def doSomething(s: String): M[Unit]
}
object AlgVect extends Alg[Vector] {
def doSomething(s: String): Vector[Unit] = Vector(println(s))
}
type Stack[E, A] = EitherT[Future, NonEmptyList[E], A]
def longRunningComputation(person: Person): Future[Either[NonEmptyList[Error], Result]] = ???
val people: List[Person] = ???
val result: Stack[Error], List[Result]] =
people.parTraverse(longRunningComputation _ andThen EitherT.apply)
@LukaJCB
LukaJCB / IO.scala
Created May 22, 2017 17:55
SimpleIOMonad
class IO[+T](run: => T) {
def map[R](f: T => R): IO[R] = {
IO(f(run))
}
def flatMap[R](f: T => IO[R]): IO[R] = {
IO(f(run).unsafeRun())
}
def unsafeRun(): T = run
module Main where
import OutWatch
import Builder ((<==))
import Control.Monad.Eff (Eff)
import Prelude (Unit, map, (#), (+))
import RxJS.Observable (interval, startWith)
main :: Eff () Unit
main = let
@LukaJCB
LukaJCB / TypeClassesDataTypes.purs
Created February 9, 2017 08:59
Why Typeclass constraints on Data types would be great.
type Container f1 f2 f3 =
{ children :: f1 String
, friends :: f2 Int
, colleagues :: f3 Number
}
data SomeType f1 f2 f3 a e = Container (Container f1 f2 f3)
| AnotherType a
| SomeEffect (Eff e Unit)
import Html exposing (beginnerProgram, div, button, text, ul, li, input, Html)
import Html.Events exposing (onClick, onInput)
import Array exposing (Array, toList, fromList, push, filter)
main =
beginnerProgram { model = initialState, view = view, update = update }
type alias Model = { list: Array String, currentText: String }
val nameStream = createInputHandler()
val component = div(
label(className := "label", "Name:"),
input(inputType := "text", input --> nameStream),
hr(),
h1("Hello ", child <-- nameStream)
)
render(document.getElementById("app"), component)
//So now after letting IntelliJ convert our file to Kotlin we get this:
//... but there's an error
class ExampleActivity : AppCompatActivity() {
private var foo: String? = "Bar"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)