sealed abstract class Result[+Err, +A] extends AnyRef
This trait represents the result of a parser.
Either a Success[A]
or a Failure
.
- A
the type of expected success result.
- Source
- Result.scala
- Alphabetic
- By Inheritance
- Result
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
get: A
Returns the successful value within the result.
Returns the successful value within the result.
This is equivalent to:
result match { case Success(x) => x case _ => throw new Exception }
- Since
1.7.0
- Exceptions thrown
java.util.NoSuchElementException
if the result is a failure.- Note
the result must not be a failure.
-
abstract
def
isFailure: Boolean
Returns
true
if this is aFailure
,false
otherwise.Returns
true
if this is aFailure
,false
otherwise.- Since
1.7.0
-
abstract
def
isSuccess: Boolean
Returns
true
if this is aSuccess
,false
otherwise.Returns
true
if this is aSuccess
,false
otherwise.- Since
1.7.0
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
contains[B >: A](elem: B): Boolean
Returns
true
if this result is aSuccess
and its value is equal toelem
(as determined by==
), returnsfalse
otherwise.Returns
true
if this result is aSuccess
and its value is equal toelem
(as determined by==
), returnsfalse
otherwise.- elem
the element to test.
- returns
true
if this is aSuccess
value equal toelem
.
- Since
1.7.0
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
exists(p: (A) ⇒ Boolean): Boolean
Returns
false
ifFailure
or returns the result of the application of the given predicate to theSuccess
value.Returns
false
ifFailure
or returns the result of the application of the given predicate to theSuccess
value.- Since
1.7.0
-
def
filterOrElse[Errʹ >: Err](p: (A) ⇒ Boolean, msg: ⇒ Errʹ): Result[Errʹ, A]
Returns
Success
with the existing value ofSuccess
if this is aSuccess
and the given predicatep
holds for the right value, orFailure(msg)
if this is aSuccess
and the given predicatep
does not hold for the right value, orFailure
with the existing value ofFailure
if this is aFailure
.Returns
Success
with the existing value ofSuccess
if this is aSuccess
and the given predicatep
holds for the right value, orFailure(msg)
if this is aSuccess
and the given predicatep
does not hold for the right value, orFailure
with the existing value ofFailure
if this is aFailure
.- Since
1.7.0
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatMap[B, Errʹ >: Err](f: (A) ⇒ Result[Errʹ, B]): Result[Errʹ, B]
Returns the result of applying
f
to this result if it is a success.Returns the result of applying
f
to this result if it is a success. Returns a failure if this result is a failure. Differs frommap
asf
returns a result instead of just a value.- Since
1.7.0
-
def
flatten[B, Errʹ >: Err](implicit ev: <:<[A, Result[Errʹ, B]]): Result[Errʹ, B]
Returns the nested result if this result is a success, otherwise return this failure.
Returns the nested result if this result is a success, otherwise return this failure.
Equivalent to
flatMap(identity[Result[Errʹ, B]])
.- Since
1.7.0
-
def
fold[B](ferr: (Err) ⇒ B, fa: (A) ⇒ B): B
Returns the result of applying
ferr
to this result's error if this is aFailure
orfa
to the result stored in theSuccess
otherwise.Returns the result of applying
ferr
to this result's error if this is aFailure
orfa
to the result stored in theSuccess
otherwise.- ferr
the function to apply if this is a
Failure
.- fa
the function to apply if this is a
Success
.- returns
the results of applying the function
- Since
1.7.0
-
def
forall(f: (A) ⇒ Boolean): Boolean
Returns
true
if this result is aFailure
or returns the result of the application of the given predicate to theSuccess
value.Returns
true
if this result is aFailure
or returns the result of the application of the given predicate to theSuccess
value.- Since
1.7.0
-
def
foreach[U](f: (A) ⇒ U): Unit
Executes the procedure
f
if this is aSuccess
.Executes the procedure
f
if this is aSuccess
. Otherwise, do nothing.This is equivalent to:
result match { case Success(x) => f(x) case _ => () }
- f
The side-effecting function to execute.
- Since
1.7.0
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getOrElse[B >: A](default: ⇒ B): B
Returns the value from this
Success
or the result of evaluatingdefault
if this is aFailure
.Returns the value from this
Success
or the result of evaluatingdefault
if this is aFailure
.- Since
1.7.0
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
map[B](f: (A) ⇒ B): Result[Err, B]
Returns a
Success
containing the result of applyingf
to this result's value if this is a success.Returns a
Success
containing the result of applyingf
to this result's value if this is a success. Otherwise, returns a failure.- Since
1.7.0
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
orElse[B >: A, Errʹ >: Err](alternative: ⇒ Result[Errʹ, B]): Result[Errʹ, B]
Returns this result if it is a
Success
, otherwise return the result of evaluatingalternative
.Returns this result if it is a
Success
, otherwise return the result of evaluatingalternative
.- Since
1.7.0
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toEither: Either[Err, A]
Converts the
Result
into aEither
whereFailure
maps to aLeft[Err]
.Converts the
Result
into aEither
whereFailure
maps to aLeft[Err]
.- Since
1.7.0
-
def
toOption: Option[A]
Returns a
Some
containing theSuccess
value if it exists or aNone
if this is aFailure
.Returns a
Some
containing theSuccess
value if it exists or aNone
if this is aFailure
.- Since
1.7.0
-
def
toSeq: Seq[A]
Returns a
Seq
containing theSuccess
value if it exists or an emptySeq
if this is aFailure
.Returns a
Seq
containing theSuccess
value if it exists or an emptySeq
if this is aFailure
.- Since
1.7.0
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
toTry: Try[A]
Converts the
Result
into aTry
whereFailure
maps to a plainException
.Converts the
Result
into aTry
whereFailure
maps to a plainException
.- Since
1.7.0
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
This is the documentation for Parsley.
Package structure
The parsley package contains the
Parsley
class, as well as theResult
,Success
, andFailure
types. In addition to these, it also contains the following packages and "modules" (a module is defined as being an object which mocks a package):parsley.Parsley
contains the bulk of the core "function-style" combinators.parsley.combinator
contains many helpful combinators that simplify some common parser patterns.parsley.character
contains the combinators needed to read characters and strings, as well as combinators to match specific sub-sets of characters.parsley.debug
contains debugging combinators, helpful for identifying faults in parsers.parsley.extension
contains syntactic sugar combinators exposed as implicit classes.parsley.expr
contains the following sub modules:parsley.expr.chain
contains combinators used in expression parsingparsley.expr.precedence
is a builder for expression parsers built on a precedence table.parsley.expr.infix
contains combinators used in expression parsing, but with more permissive types than their equivalents inchain
.parsley.expr.mixed
contains combinators that can be used for expression parsing, but where different fixities may be mixed on the same level: this is rare in practice.parsley.implicits
contains several implicits to add syntactic sugar to the combinators. These are sub-categorised into the following sub modules:parsley.implicits.character
contains implicits to allow you to use character and string literals as parsers.parsley.implicits.combinator
contains implicits related to combinators, such as the ability to make any parser into aParsley[Unit]
automatically.parsley.implicits.lift
enables postfix application of the lift combinator onto a function (or value).parsley.implicits.zipped
enables boths a reversed form of lift where the function appears on the right and is applied on a tuple (useful when type inference has failed) as well as a.zipped
method for building tuples out of several combinators.parsley.errors
contains modules to deal with error messages, their refinement and generation.parsley.errors.combinator
provides combinators that can be used to either produce more detailed errors as well as refine existing errors.parsley.errors.tokenextractors
provides mixins for common token extraction strategies during error message generation: these can be used to avoid implementingunexpectedToken
in theErrorBuilder
.parsley.lift
contains functions which lift functions that work on regular types to those which now combine the results of parsers returning those same types. these are ubiquitous.parsley.ap
contains functions which allow for the application of a parser returning a function to several parsers returning each of the argument types.parsley.registers
contains combinators that interact with the context-sensitive functionality in the form of registers.parsley.token
contains theLexer
class that provides a host of helpful lexing combinators when provided with the description of a language.parsley.position
contains parsers for extracting position information.parsley.genericbridges
contains some basic implementations of the Parser Bridge pattern (see Design Patterns for Parser Combinators in Scala, or the parsley wiki): these can be used before more specialised generic bridge traits can be constructed.