What is a Pull, taken from a Gitter thread.
All comments are by Fabio Labella @SystemFw unless specified.
[1] https://gitter.im/functional-streams-for-scala/fs2?at=5acb7b81109bb04332a39a41
What is a Pull
| module MyParser where | |
| import Text.Read (readMaybe) | |
| newtype Parser a = Parser { runParser :: String -> Either String (a, String) } | |
| parseChar :: Char -> Parser Char | |
| parseChar char = | |
| Parser $ \input -> | |
| case input of |
| {-# LANGUAGE OverloadedStrings #-} | |
| {-# LANGUAGE QuasiQuotes #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| module ExampleErrorSpec where | |
| import Test.Hspec | |
| import Test.Hspec.Wai | |
| spec :: Spec |
What is a Pull, taken from a Gitter thread.
All comments are by Fabio Labella @SystemFw unless specified.
[1] https://gitter.im/functional-streams-for-scala/fs2?at=5acb7b81109bb04332a39a41
What is a Pull
What is a Pull, taken from a Gitter thread.
All comments are by Fabio Labella @SystemFw unless specified.
[1] https://gitter.im/functional-streams-for-scala/fs2?at=5acb7b81109bb04332a39a41
What is a Pull
| import fs2.Stream | |
| import fs2.Pipe | |
| import fs2.Chunk | |
| import fs2.Pull | |
| import cats.effect.IO | |
| import scala.language.higherKinds | |
| //implementing scan from https://fs2.io/guide.html#exercises-stream-transforming | |
| //Stream.range(1,10).scan(0)(_ + _).toList // running sum | |
| // res38: List[Int] = List(0, 1, 3, 6, 10, 15, 21, 28, 36, 45) |
| //I'm trying to implement `intersperse` from : https://fs2.io/guide.html#exercises-stream-transforming | |
| import fs2.Stream | |
| import fs2.Pipe | |
| import fs2.Chunk | |
| import fs2.Pull | |
| import cats.effect.IO | |
| import scala.language.higherKinds | |
| object Intersperse { |
| count :: Int -> IO Int | |
| count it | |
| | it <= 0 = pure 0 | |
| | otherwise = | |
| do | |
| n <- count (it - 1) | |
| pure (n + 1) |
| scala> trait A { val a: String = "this is A" } | |
| defined trait A | |
| scala> trait B { val b: String = "this is B" } | |
| defined trait B | |
| scala> trait C { val c: String = "this is C" } | |
| defined trait C | |
| scala> val abc = new A with B with C |
| type ErrorOr[A] = Either[String, A] | |
| def errors(error: String): () => ErrorOr[Int] = () => { | |
| println(s"running $error") | |
| Left(error) | |
| } | |
| scala> val item1 = errors("error1") | |
| item1: () => ErrorOr[Int] = $$Lambda$4361/1034150118@23f4a773 |
| {-# LANGUAGE OverloadedStrings #-} | |
| module Milo.Blog where | |
| import qualified Data.Text as T | |
| import qualified Data.Text.IO as TIO | |
| import qualified Data.Text.Encoding as E | |
| import qualified Data.ByteString.Lazy as LBS | |
| import qualified Data.ByteString.Lazy.Char8 as LBS8 | |
| import qualified Data.Aeson as A (Value(String)) |