Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typeclasses laws #112

Merged
merged 37 commits into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4e0c797
FunctorLaws test + example impl over Option
raulraja Jun 12, 2017
d8d8148
Submitting reified bug to origin to show in Kotlin's slack
raulraja Jun 14, 2017
a85100b
Fixed functor laws working arounf reified and kotlin test bug on Gen.…
raulraja Jun 14, 2017
f26280b
Functor first please! (to allow type constructors of different arity)
raulraja Jun 14, 2017
f13f5c8
El primogenito.
raulraja Jun 14, 2017
6d9fe8f
Added Applicative Laws
raulraja Jun 15, 2017
dda1eef
Merge branch 'master' into rr-discipline
raulraja Jun 15, 2017
0c962d0
Create README.md (#113)
raulraja Jun 15, 2017
c797404
Monad Laws and some instance showing stack-safety bugs
raulraja Jun 19, 2017
85a1db4
Merge remote-tracking branch 'origin/rr-discipline' into rr-discipline
raulraja Jun 19, 2017
93d92c2
Perform renames towards "kategory" as the lib name (#114)
wiyarmir Jun 21, 2017
40b8708
Add Maven publish configurations (#115)
wiyarmir Jun 21, 2017
79e13a5
release version 0.3.3
ffgiraldez Jun 21, 2017
689e16b
bump next version
ffgiraldez Jun 21, 2017
ac359f6
refactor rename test folder from katz to kategory
Guardiola31337 Jun 22, 2017
bba71ad
FunctorLaws test + example impl over Option
raulraja Jun 12, 2017
8691cfd
Submitting reified bug to origin to show in Kotlin's slack
raulraja Jun 14, 2017
dc18c45
Fixed functor laws working arounf reified and kotlin test bug on Gen.…
raulraja Jun 14, 2017
4224f40
Functor first please! (to allow type constructors of different arity)
raulraja Jun 14, 2017
65a9583
El primogenito.
raulraja Jun 14, 2017
682dc3c
Added Applicative Laws
raulraja Jun 15, 2017
736102c
Monad Laws and some instance showing stack-safety bugs
raulraja Jun 19, 2017
5d2e9f8
Rebased master
raulraja Jun 23, 2017
2290a72
Merge remote-tracking branch 'origin/rr-discipline' into rr-discipline
raulraja Jun 23, 2017
889bb0c
Fixed Either Monad SO issues
raulraja Jun 23, 2017
8e54481
Laws on EitherT monad
raulraja Jun 23, 2017
c534dd0
Fixed SO on Function0 but still equality is broken
raulraja Jun 23, 2017
82d0ec4
Id monad laws passing
raulraja Jun 23, 2017
d16f141
Fixed Ior Monad
raulraja Jun 23, 2017
5c93586
MonadLaws for NonEmptyList and safer monad impl
raulraja Jun 23, 2017
05b7f93
MonadLaws for OptionT
raulraja Jun 23, 2017
fe89c2c
MonadLaws for Try
raulraja Jun 23, 2017
8d42012
MonadLaws for WriterT
raulraja Jun 23, 2017
2557b23
ApplicativeLaws for Validated
raulraja Jun 23, 2017
18e6b3e
MonadLaws for Free failing on equality comparisons of the internal ADTs
raulraja Jun 23, 2017
3c476b5
remove `open` mod in EitherMonad
raulraja Jun 23, 2017
b7108d7
s/Kleisi/Kleisli
raulraja Jun 23, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Copyright (C) 2017 The Katz Authors
Copyright (C) 2017 The Kategory Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@ A copy of Apache License 2.0 has been included at the end of this file.

------------------------------------------------------------------------

Code in Katz is derived in part from typelevel/Cats and Scalaz.
Code in Kategory is derived in part from typelevel/Cats and Scalaz.

Cats license follows:

Expand Down
49 changes: 9 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,23 @@
Katz
Kategory
====
[![Build Status](https://travis-ci.org/FineCinnamon/Katz.svg?branch=master)](https://travis-ci.org/FineCinnamon/Katz/)
[![Build Status](https://travis-ci.org/kategory/kategory.svg?branch=master)](https://travis-ci.org/kategory/kategory/)
[![Kotlin version badge](https://img.shields.io/badge/kotlin-1.1.3.dev.1450-blue.svg)](http://kotlinlang.org/)
[![Hex.pm](https://img.shields.io/hexpm/l/plug.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![codecov](https://codecov.io/gh/FineCinnamon/Katz/branch/master/graph/badge.svg)](https://codecov.io/gh/FineCinnamon/Katz)
[![version](https://jitpack.io/v/FineCinnamon/Katz.svg)](https://jitpack.io/#FineCinnamon/Katz/)
[![codecov](https://codecov.io/gh/kategory/kategory/branch/master/graph/badge.svg)](https://codecov.io/gh/kategory/kategory)
[![version](https://jitpack.io/v/kategory/kategory.svg)](https://jitpack.io/#kategory/kategory/)

Functional Datatypes and abstractions for Kotlin inspired by [Cats][cats]

# How to contribute

If you are thinking about contributing to the project, you should read the following lines about the basics of the contribution philosophy we have:

* All the FP types use similar combinators. Some of them are capable of supporting just a subset of those operations, and other ones support a different subset. But in the end we have no more than a set of N given combinators that we can find in almost all the FP types.
* The intention of **Katz** this library is to create a straightforward and simple API.
* For the types we add, we should think about the operations we can find on `Semigroup`, `Monoid`, `Foldable`, `Traversable`, `Functor`, `Applicative`, `Monad`..., and provide them in the types that can support them.
* For those operations, you should always follow the same naming and form to kind off keep the standards.

This approach is going to give us the possibility to Learn that all the computation aspects can be resolved by identifying the abstractions and always using the same combinators, independently of the data type they are expressed on. In example:

* We will find `Functor.map` in `Option`, `List`, `Future`... and so on.
* We will find `Applicative.pure` on those types also.
* ... and the same way with all the combinators we are going to implement.

Since `Kotlin` does not support `HKTs` we are going to code all the combinators in each one of the types, but at the same time, that's a good practice to learn how the same operations can be applied to different types in functional programing. So you normally have:

* A data structure with an ADT representing it's concrete states.
* The structure is recursive, so you can iterate over it and use pattern matching over it's subtypes (ADT types) representing it's different concrete state implementations.
* This recursion can be expressed with a `fold`.
* That `fold` is the base for the rest of the combinators.

If you follow this pattern, you will see by yourself how functional programing libraries are implemented, and you are going to know how to do pure functional programing using immutable data structures.

## The need to not overoptimize using Kotlin

Once we have the pure functional base, we can start adding `Kotlin` optimizations over it using the language's syntatic sugar. But **we need to put attention on creating correct definitions over performance improvements or any type of early micro-optimization.**

Ideally, we would want to have property based tests where we would apply a series of norms over the base abstractions in each one of the types implemented.

# Add it to your project

Use it at your how risk, the actual state is not production ready.

Add it in your root `build.gradle` at the end of repositories.

```
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
maven { url "http://dl.bintray.com/kategory/maven" }
maven { url 'https://kotlin.bintray.com/kotlinx' }
maven { url "http://dl.bintray.com/kotlin/kotlin-dev" }
}
Expand All @@ -57,15 +26,15 @@ allprojects {

Add the dependency into project `build.gradle`

```
```groovy
dependencies {
compile 'com.github.FineCinnamon:Katz:v0.2'
compile 'io.kategory:kategory:0.3.3'
}
```

# License

Copyright (C) 2017 The Katz Authors
Copyright (C) 2017 The Kategory Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
28 changes: 20 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Katz Authors
* Copyright (C) 2017 The Kategory Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,8 +21,7 @@ buildscript {
// Constants
gradleVersion = '3.5'
gradleVersionsPluginVersion = '0.15.0'
javaVersion = '1.7'
katzVersion = '0.1-SNAPSHOT'
javaVersion = JavaVersion.VERSION_1_7
kotlinTestVersion = '2.0.3'
kotlinVersion = '1.1.4-dev-600'
kotlinxCollectionsImmutableVersion = '0.1'
Expand All @@ -37,23 +36,25 @@ buildscript {
dependencies {
classpath "com.github.ben-manes:gradle-versions-plugin:$gradleVersionsPluginVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
}

allprojects {
subprojects { project ->

group = GROUP
version = VERSION_NAME

repositories {
jcenter()
maven { url 'https://kotlin.bintray.com/kotlinx' }
maven { url "http://dl.bintray.com/kotlin/kotlin-dev" }
}

apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'jacoco'

group = 'com.github.finecinnamon'
archivesBaseName = project.name
version = katzVersion

jacoco {
toolVersion '0.7.8'
Expand All @@ -68,13 +69,24 @@ allprojects {
}

classDirectories = fileTree(
dir: 'build/classes/main/katz',
dir: 'build/classes/main/kategory',
)

sourceDirectories = files('src/main/kotlin')
executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
}

apply plugin: 'com.jfrog.bintray'
bintray {
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
configurations = ['archives']
pkg {
repo = 'maven'
name = POM_ARTIFACT_ID
userOrg = POM_DEVELOPER_ID
}
}
}

task wrapper(type: Wrapper) {
Expand Down
50 changes: 19 additions & 31 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
#
# Copyright (C) 2017 The Katz Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Package definitions
GROUP=io.kategory
VERSION_NAME=0.3.4-SNAPSHOT

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Gradle options
org.gradle.jvmargs=-Xmx2048m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# Kotlin configuration
kotlin.coroutines=enable
kotlin.incremental=true

# Pomfile definitions
POM_DESCRIPTION=Functional Datatypes and abstractions for Kotlin inspired by Cats.

POM_URL=https://github.com/kategory/kategory/
POM_SCM_URL=https://github.com/kategory/kategory/
POM_SCM_CONNECTION=scm:git:git://github.com/kategory/kategory.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/kategory/kategory.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=kategory
POM_DEVELOPER_NAME=The Kategory Authors
158 changes: 158 additions & 0 deletions gradle/gradle-mvn-push.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright 2013 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'maven'
apply plugin: 'signing'

version = VERSION_NAME
group = GROUP

def isReleaseBuild() {
return !VERSION_NAME.contains("SNAPSHOT")
}

def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
}

afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}

if (project.hasProperty("signArchives")) {
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
}

install {
repositories.mavenInstaller {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}

artifacts {
archives sourcesJar
archives javadocJar
}
}
Loading