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

FreeC implementation #1048

Merged
merged 19 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,85 @@ probabilistik license follows:
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.

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

Code in Arrow is derived in part from functional-streams-for-scala/fs2.

fs2 license follows:

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

The MIT License (MIT)

Copyright (c) 2013 Paul Chiusano, and respective contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Code in FS2 is derived in part from Cats. The Cats license is as follows:

Cats Copyright (c) 2015 Erik Osheim.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

------

Code in Cats is derived in part from Scalaz. The Scalaz license follows:

Copyright (c) 2009-2014 Tony Morris, Runar Bjarnason, Tom Adams,
Kristian Domagala, Brad Clow, Ricky Clarkson, Paul Chiusano, Trygve
Laugstøl, Nick Partridge, Jason Zaugg. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fun <T> Option<T>.getOrElse(default: () -> T): T = fold({ default() }, ::identit
*
* @param alternative the default option if this is empty.
*/
inline fun <A, B : A> OptionOf<B>.orElse(alternative: () -> Option<B>): Option<B> = if (fix().isEmpty()) alternative() else fix()
inline fun <A> OptionOf<A>.orElse(alternative: () -> Option<A>): Option<A> = if (fix().isEmpty()) alternative() else fix()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice one


infix fun <T> OptionOf<T>.or(value: Option<T>): Option<T> = if (fix().isEmpty()) {
value
Expand Down
1 change: 1 addition & 0 deletions modules/core/arrow-free/src/main/kotlin/arrow/free/Free.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fun <S, A, B> FreeOf<S, A>.flatMap(f: (A) -> Free<S, B>): Free<S, B> = Free.Flat

fun <S, A, B> FreeOf<S, A>.ap(ff: FreeOf<S, (A) -> B>): Free<S, B> = ff.fix().flatMap { f -> map(f = f) }.fix()

/** Takes one evaluation step in the Free monad, re-associating left-nested binds in the process. */
@Suppress("UNCHECKED_CAST")
tailrec fun <S, A> Free<S, A>.step(): Free<S, A> =
if (this is Free.FlatMapped<S, A, *> && this.c is Free.FlatMapped<S, *, *>) {
Expand Down
15 changes: 15 additions & 0 deletions modules/streams/arrow-streams/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dependencies {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 it's alive!

compile project(':arrow-effects')
compile project(':arrow-instances-data')
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
testCompile "io.kotlintest:kotlintest:$kotlinTestVersion"
testCompile project(':arrow-test')
testCompile project(':arrow-effects-instances')

compile project(':arrow-annotations')
kapt project(':arrow-annotations-processor')
kaptTest project(':arrow-annotations-processor')
}

apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
apply plugin: 'kotlin-kapt'
4 changes: 4 additions & 0 deletions modules/streams/arrow-streams/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Maven publishing configuration
POM_NAME=Arrow-Streams
POM_ARTIFACT_ID=arrow-streams
POM_PACKAGING=jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package arrow.effects

//Temp copy until https://github.com/arrow-kt/arrow/pull/1043 is merged
sealed class ExitCase<out E> {
object Completed : ExitCase<Nothing>()
object Cancelled : ExitCase<Nothing>()
data class Error<out E>(val e: E) : ExitCase<E>()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package arrow.streams

import arrow.core.*
import arrow.data.Nel
import arrow.data.NonEmptyList

/** Represents multiple (>1) exceptions were thrown. */
data class CompositeFailure(
val head: Throwable,
val tail: Nel<Throwable>
) : Throwable("Multiple exceptions were thrown (${1 + tail.size}), first $head: ${head.message}", head) {

/** Gets all causes (guaranteed to have at least 2 elements). */
val all: NonEmptyList<Throwable> = Nel(head, tail.all)

companion object {
operator fun invoke(first: Throwable, second: Throwable, rest: List<Throwable> = emptyList()): CompositeFailure =
CompositeFailure(first, Nel(second, rest))

fun fromList(error: List<Throwable>): Option<Throwable> = when {
error.isEmpty() -> None
error.size == 1 -> Some(error[0])
else -> Some(invoke(error[0], error[1], error.drop(2)))
}

/**
* Builds composite failure from the results supplied.
*
* - When any of the results are on left, then the Left(err) is returned
* - When both results fail, the Left(CompositeFailure(_)) is returned
* - When both results succeeds then Right(()) is returned
*
*/
fun fromResults(first: Either<Throwable, Unit>,
second: Either<Throwable, Unit>): Either<Throwable, Unit> = when (first) {
is Either.Right -> second
is Either.Left -> when (second) {
is Either.Left -> Left(CompositeFailure(first.a, second.a, emptyList()))
is Either.Right -> Left(first.a)
}
}
}
}

Loading