Coder Social home page Coder Social logo

papa's Introduction

CSIRO's Data61 Logo

papa

Top-level package for general libraries. To import all modules in all sub-packages:

import Papa

Package dependency tree:

  • papa Top-level package which exports all other packages in papa-*.

    • papa-base Exports modules from the base package that are safe and useful to have re-exported into default scope. Implements useful, general library functions that depend only on base.

      • papa-base-export Exports safe and useful functions from base.

      • papa-base-implement Implements safe and useful functions that depend only on base.

    • papa-bifunctors Exports modules from the third-party bifunctors package that are safe and useful to have re-exported into default scope. Implements useful, general library functions that depend only on bifunctors.

      • papa-bifunctors-export Exports safe and useful functions from bifunctors.

      • papa-bifunctors-implement Implements safe and useful functions that depend only on bifunctors.

    • papa-example Example use of the papa packages.

    • papa-lens Exports modules from the third-party lens package that are safe and useful to have re-exported into default scope. Implements useful, general library functions that depend only on lens.

      • papa-lens-export Exports safe and useful functions from lens.

      • papa-lens-implement Implements safe and useful functions that depend only on lens.

    • papa-semigroupoids Exports modules from the third-party semigroupoids package that are safe and useful to have re-exported into default scope. Implements useful, general library functions that depend only on semigroupoids.

      • papa-semigroupoids-export Exports safe and useful functions from semigroupoids.

      • papa-semigroupoids-implement Implements safe and useful functions that depend only on semigroupoids.

    • papa-x Exports modules from arbitrary third-party packages that are safe and useful to have re-exported into default scope. Implements useful, general library functions that depend on arbitrary third-party packages.

      • papa-x-export Exports safe and useful functions from arbitrary third-party packages.

      • papa-x-implement Implements safe and useful functions that depend on arbitrary third-party packages.

papa's People

Contributors

ajmcmiddlin avatar dalaing avatar enemeth79 avatar gwils avatar lightandlight avatar nkpart avatar puffnfresh avatar tonymorris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

papa's Issues

Bool library

Get this one done once and for all.

{-# LANGUAGE FlexibleInstances #-}

import Control.Category(Category(id))
import Control.Lens
import Data.Bool
import Data.Monoid
import Prelude hiding (id)

class GetBool a where
  _GetBool ::
    Getter a Bool

instance GetBool Bool where
  _GetBool =
    id

instance GetBool Any where
  _GetBool =
    _Wrapped

instance GetBool All where
  _GetBool =
    _Wrapped

instance GetBool (Dual Bool) where
  _GetBool =
    _Wrapped

instance GetBool (First ()) where
  _GetBool =
    to (\(First x) -> maybe False (\() -> True) x)

instance GetBool (Last ()) where
  _GetBool =
    to (\(Last x) -> maybe False (\() -> True) x)

cprogrammer :: 
  (Contravariant f, Profunctor p, Num a, Functor f, Eq a) =>
  Optic' p f a Bool
cprogrammer = 
  to (== 0)

instance GetBool Int where
  _GetBool =
    cprogrammer

instance GetBool Integer where
  _GetBool =
    cprogrammer

instance GetBool Word where
  _GetBool =
    cprogrammer

instance (Eq a, Num a) => GetBool (Identity a) where
  _GetBool =
    cprogrammer

instance (Eq a, Num a) => GetBool (Const a b) where
  _GetBool =
    cprogrammer

instance (Eq a, Num a) => GetBool (Sum a) where
  _GetBool =
    cprogrammer

instance GetBool Float where
  _GetBool =
    cprogrammer

instance GetBool Double where
  _GetBool =
    cprogrammer

class GetBool a => IsBool a where
  _Bool ::
    Iso' a Bool

instance IsBool Bool where
  _Bool =
    id

instance IsBool Any where
  _Bool =
    _Wrapped

instance IsBool All where
  _Bool =
    _Wrapped

instance IsBool (Dual Bool) where
  _Bool =
    _Wrapped

instance IsBool (First ()) where
  _Bool =
    iso
      (view _GetBool)
      (First . bool Nothing (Just ()))

instance IsBool (Last ()) where
  _Bool =
    iso
      (view _GetBool)
      (Last . bool Nothing (Just ()))

true ::
  IsBool a =>
  a
true =
  True ^. from _Bool
  
false ::
  IsBool a =>
  a
false =
  False ^. from _Bool

if' ::
  GetBool a =>
  x
  -> x
  -> a
  -> x
if' f t a =
  if a ^. _GetBool then t else f

ifB ::
  (GetBool a, Monad f) => -- todo use Bind, not Monad
  f x
  -> f x
  -> f a
  -> f x
ifB f t a =
  a >>= if' f t

(?.) ::
  (Category c, IsBool a) =>
  c x x
  -> a
  -> c x x
(?.) =
  if' id

(?<>) ::
  (Monoid x, IsBool a) =>
  x
  -> a
  -> x
(?<>) =
  if' mempty

(?<*>) ::
  (Applicative f, GetBool a) => 
  (x -> f x)
  -> a
  -> x
  -> f x
(?<*>) =
  if' pure

(?@) ::
  (Applicative f, GetBool a) =>
  f ()
  -> a
  -> f ()
(?@) =
  if' (pure ())

(!?.) ::
  (Category c, IsBool a) =>
  c x x
  -> a
  -> c x x
(!?.) =
  (`if'` id)

(!?<>) ::
  (Monoid x, IsBool a) =>
  x
  -> a
  -> x
(!?<>) =
  (`if'` mempty)

(!?<*>) ::
  (Applicative f, GetBool a) => 
  (x -> f x)
  -> a
  -> x
  -> f x
(!?<*>) =
  (`if'` pure)

(!?@) ::
  (Applicative f, GetBool a) =>
  f ()
  -> a
  -> f ()
(!?@) =
  (`if'` (pure ()))

Compile on windows

All the papa-* packages do not compile on windows due to the funky Setup.lhs file and associated funky build configuration.

We should fix this.

Test with Travis or similar

Papa should be built on all supported GHC versions on every commit. In other projects we're using Travis CI for this, so we should set that up here too.

catMaybes and mapMaybe written generally

Belongs in papa-lens-implement

import Control.Lens
import Data.Monoid

newtype Compose f g a =
  Compose (f (g a))

instance (Foldable f, Foldable g) => Foldable (Compose f g) where
  foldr f z (Compose x) =
    foldr (\a b -> foldr f b a) z x

collapse0 ::
 (Cons r r a a, AsEmpty r) =>
 Getting (Endo r) s a
 -> s
 -> r
collapse0 x =
  foldrOf x cons (_Empty # ())

collapse1 ::
  (Cons r r a a, AsEmpty r) =>
  Getting (Endo r) (Compose f g b) a
  -> f (g b)
  -> r
collapse1 x =
  collapse0 x . Compose

collapse2 ::
  (Cons r r a a, AsEmpty r) =>
  Getting (Endo r) (Compose (Compose f g) h b) a
  -> f (g (h b))
  -> r
collapse2 x =
  collapse1 x . Compose

map1 ::
  (Cons r r a a, AsEmpty r, Functor f) =>
  Getting (Endo r) (f c) a
  -> (b -> c)
  -> f b
  -> r
map1 x f =
  collapse0 x . fmap f

map2 ::
  (Cons r r a a, AsEmpty r, Functor f) =>
  Getting (Endo r) (Compose f g c) a
  -> (b -> g c)
  -> f b
  -> r
map2 x f =
  collapse1 x . fmap f

map3 ::
  (Cons r r a a, AsEmpty r, Functor f) =>
  Getting (Endo r) (Compose (Compose f g) h c) a
  -> (b -> g (h c))
  -> f b
  -> r
map3 x f =
  collapse2 x . fmap f

----

mapMaybe ::
  (a -> Maybe b)
  -> [a]
  -> [b]
mapMaybe = 
  map2 folded

catMaybes ::
  [Maybe a]
  -> [a]
catMaybes =
  collapse1 folded

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.