Skip to content

Commit

Permalink
Seperate Scala 2/3 INothing
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Nov 19, 2021
1 parent c149ceb commit 744013e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
version = 3.1.1

runner.dialect = Scala213Source3
fileOverride {
"glob:**/scala-3/**/*.scala" {
runner.dialect = scala3
}
"glob:**/scala-2.13/**/*.scala" {
runner.dialect = scala213
}
}

maxColumn = 96

Expand Down
38 changes: 38 additions & 0 deletions lambda/shared/src/main/scala-3/feral/lambda/INothing.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2021 Typelevel
*
* 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 feral.lambda

import io.circe.Encoder

import scala.annotation.nowarn

/**
* Alias for `Nothing` which works better with type inference. Inspired by fs2, but inlined here
* to avoid pulling in an otherwise-unnecessary dependency.
*/
type INothing <: Nothing
object INothing {

/**
* This can't actually be used. It's here because `IOLambda` demands an Encoder for its result
* type, which should be `Nothing` when no output is desired. Userland code will return an
* `Option[Nothing]` which is only inhabited by `None`, and the encoder is only used when the
* userland code returns `Some`.
*/
@nowarn("msg=dead code following this construct")
implicit val nothingEncoder: Encoder[INothing] = (_: INothing) => ???
}
19 changes: 19 additions & 0 deletions lambda/shared/src/main/scala-3/feral/lambda/Lambda.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2021 Typelevel
*
* 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 feral.lambda

type Lambda[F[_], Event, Result] = (Event, Context[F]) => F[Option[Result]]

0 comments on commit 744013e

Please sign in to comment.