Giter Club home page Giter Club logo

arrow-kt / arrow Goto Github PK

View Code? Open in Web Editor NEW
6.0K 6.0K 436.0 52.34 MB

Λrrow - Functional companion to Kotlin's Standard Library

Home Page: http://arrow-kt.io

License: Other

Kotlin 99.98% Java 0.02%
arrow continuations coroutines delimited-continuations for-comprehension fp-types functional-data-structure functional-programming hacktoberfest kotlin kotlin-dsl kotlin-libraries kotlin-library monads optics polymorphism typeclasses typed-lambda-calculus

arrow's People

Contributors

1jajen1 avatar aballano avatar abendt avatar aedans avatar andrzejressel avatar atternatt avatar calvellido avatar cotel avatar danimontoya avatar ffgiraldez avatar franciscodr avatar guardiola31337 avatar i-walker avatar israelperezglez avatar javiersegoviacordoba avatar jmpergar avatar jorgecastilloprz avatar jrgonzalezg avatar marioariasc avatar nomisrev avatar npatarino avatar pablisco avatar pakoito avatar rachelcarmena avatar raulraja avatar renovate[bot] avatar serras avatar tonilopezmr avatar victorg1991 avatar wiyarmir 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  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  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  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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar

arrow's Issues

Add katz-rx module

There is a good chance of experimenting integration with existing apps and frameworks, and RxJava seems like a natural fit. We're looking for someone to take on the following subtasks:

  • create a new module depending on katz and RxJava 2.X
  • add instances of Monad, Foldable and Traversable for Observable
  • introduce some tests and examples of using Observable using imperative binding notation

The estimated effort is around 500-700 lines of code. The maintainers compromise to help and support whomever is completing this ticket, as it'll help assess the difficulty of applying the concepts for newcomers.

Create StateT type

This implementation will be a simplification as we don't have HKTs yet

Create Traverse

Requirements

Traverse needs to be done in terms of Foldable, so we need to wait for #62 to be done.

Add mapOf for Tuple2

Create a mapOf function to build a Map from Tuple2 as the mapOf (in kotlin-stdlib) builds a Map from Pair

Const and Nested combined types + missing Traverse laws

Ensure all instances delegate to existing datatypes combinators.

It's common to stack overflow if instances of Monad for example don't provide overrides that delegate to the Datatype impl which is usually the shortest and more efficient path.

For example when creating an instance for Monad and your datatype contains map, ap and others, do not let the methods in the Monad hierarchy to stay autoimplemented and provide instead overrides that delegate to the datatype because the default implementations are usually non-effitient and can lead to stack overflow errors.

For example Monad implements ap in terms of flatMap, and Applicative implements map in terms of ap. While this may be ok for simple datatypes it's gonna blow up in cases such as EitherT and other more complex ones.

Each datatype should have separate classes for each instance it implements for example. Instead of having a single IdMonad we should have IdMonad: IdApplicative and IdApplicative: IdFunctor and so on where in each class there is a delegation of the corresponding methods to the ones present in the datatype.

Add WriterT monad

Taking this one because I've never looked into the writer monad so, yeah.

Add Vector construct

Add NonEmptyVector construct

Stack safe flag for comprehensions over stack-unsafe monads

Since the coroutine system allows us to invoke resume when we want the coroutine to proceed we could potentially exploit that so that if the user indicates that he wants the monadic comprehension to be stack safe even if the underlying monad is not stacksafe we could explicitly trampoline before calling resume. from a usage point of view it would be transparent to the user and it would be just an extra param to the binding block:

Option.binding(StackSafe) {
      ...
}

Roadmap

Roadmap

data

  • Option
  • Try
  • Either
  • Ior
  • Coproduct
  • Free
  • Cofree #92
  • Trampoline #77
  • Coyoneda #80
  • FreeApplicative #164
  • NonEmptyList
  • Vector #97
  • NonEmptyVector #96
  • OptionT
  • StateT #14
  • WriterT #84
  • EitherT
  • Kleisli
  • Cokleisli #86
  • Function0 #95
  • Function1 #137
  • PartialFunction + case syntax #143

typeclasses

  • Functor (improved by #173)
  • FunctorFilter #224
  • Applicative
  • ApplicativeError
  • Monad
  • MonadError
  • MonadCombine (#248 Work in progress)
  • MonadFilter #242
  • MonadReader
  • MonadState #145
  • MonadWriter #210
  • Semigroup
  • SemigroupK #149
  • Monoid
  • MonoidK #151
  • Foldable
  • Traverse
  • Reducible #215
  • TraverseFilter (#255 Work In Progress)
  • Inject
  • FunctionK
  • Choice

instances

  • all instances of typeclasses that can be applied over defined datatypes and those from the kotlin stdlib

syntaxis

  • syntax for all types which in some way implement a typeclass either directly or through companion.
  • tuple destructuring #99

utils

  • monadic comprehensions
  • comonadic comprehensions #88
  • cartesian builder
  • find a way to register implicit typeclasses with arity 2+

tests

  • discipline #65
  • missing traverse laws #136

docs

  • Docs for each data type and type class including example use cases

Fix snapshot deploys

Jitpack is not doing snapshot deploys properly due to incremental compilation errors. If any one has experienced this problem lately and knows how to force disable it for Jitpack, that would be helpful.

Snapshots are important also and enables anybody (not just us) to test the library on different projects and give good feedback.

Creating a new data type

This document is a brain dump from the stuff I've been working on lately around data types. Instances to come on a separate issue.

Data types

Example: https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/data/WriterT.kt

The file reads as follows:

package

package katz // we want all imports together for now

alias

typealias MyTypeKind<...> = HK_N_<MyType.F, ...> // This defines the higher kind this type belongs to. N is the number of parameters in ...

typealias MyTypeF<...> = HK_N - 1_<MyType.F, ...> // A partially applied type generally used for typeclass instances

evaluation

Here we use extension methods parametrized on generics to add functionality to specific types. This is a cool kotlin-exclusive feature you need to familiarize with. It has the advantage of not forcing inheritance, and they're found by the compiler using a type lookup. If you try to use it on a tag type you haven't defined for, you'll get a very verbose error message to tell you the lookup failed.

fun <A, B> MyTypeKind<...>.ev(): MyType<...> = this as MyType<...> // This brings the higher kind back into the implementation using a safe unchecked cast

fun MyTypeKind.value(): A = this.value // For simple wrappers types like Id this helper can be added to retrieve the value

constructor

data class MyType<...>(val ...): MyTypeKind<...>

Data class to get equals and hashCode. Some data types may require using a sealed class instead, like Either or Optional do.

Use the kind typealias for the HK tag.

tag type

class F private constructor()

This type cannot be instanced and is used exclusively in higher kinds to enable .ev() to be inferred correctly

companion object

The companion object's duty is to hold all the smart constructors for the variations of the type. Provide at least one that'll correspond to pure() for the monad.

reified constructors

One common pattern used for smart constructors is overloading the invoke operator. The operator can be inlined, which enables reified generics. With reified generics, you can call the methods used for global injection of typeclass instances. This methods are named after the typeclass, so you can use monad(), foldable(), applicable()...

injection of typeclass instances

TEMPORARY HACK. ONLY AVAILABLE FOR NON-PARAMETRIZED INSTANCES:

Example: https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/data/NonEmptyList.kt#L62

GlobalInstance<A: Typeclass> is a helper that takes the Typeclass defined by A and adds it to a global map. This makes it available to be found using the global injection functions like monad() or functor().

instance methods

Generally recommended to implement map and flatMap here. Other useful methods are fold, foldr/foldl, traverse, extract, and coflatMap.

These will be used by the typeclass instances directly, and can be enhanced from the required canonical implementation.

Eliminate some of the syntactic options of for comprehensions

As per #31 there are three possible approaches to comprehensions:

optionMonad.binding {
  val a = bind { monad }
  val b = monad.bind()
  val c = ! monad
  yields { a + b + c }
}

After the library has been in prod, and if widespread, consider elimination at least one of the options based off usage.

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.