E07830: unable to find a '|' pipe operator for type

Category: E07xxx Full resolution · Reported in phase: FULL_RESOLUTION · Classification: UNABLE_TO_FIND_PIPE_FOR_TYPE · All error codes

What went wrong

You're trying to use a type in a stream pipeline with 'collect as' but it doesn't have the pipe operator '|' defined.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 124 (How do I group and aggregate collection data in EK9?)
  • ek9 -q 89 (How do I use streams and stream pipelines in EK9?)
  • ek9 -q 123 (How do I flatten nested collections and optionals in EK9?)
  • ek9 -q 125 (How do I use head, tail, and skip to limit streams in EK9?)

[EK9 STREAM PIPELINES] The streaming mechanism uses the pipe '|' symbol for joining parts of the pipeline (like Unix). Stream operations include:

  • filter/reject, map, sort, group, join, split, uniq, tee, head, tail

When you use 'collect as YourType', EK9 merges stream items into a single result using the '|' operator.

How to fix it

  1. Give the type an 'operator |' that takes the stream's element type (it receives one item at a time and folds it into the object)
  2. Or stream into a built-in collection instead ('collect as List of Integer', or '> list' into a List you already hold)

The [EXAMPLE] section below shows a collector whose '|' takes a Duration fed Integers, and the same collector fed Durations.

See also

  • E07830: missing pipe operator for collect (this error)
  • E07840: missing iterator for cat

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E07830: unable to find a '|' pipe operator for type

#!ek9
defines module error.e07830.bad

  defines class

    DurationCollector
      total as Duration: Duration()

      default operator ?

      operator |
        -> item as Duration
        total += item

  defines function

    collectAll()
      collector <- DurationCollector()

      //The collector has a '|' for Duration, not for Integer
      cat [1, 2, 3] >> collector

Fixed: Pipe in what the collector has a '|' for

#!ek9
defines module error.e07830.good.fix

  defines class

    DurationCollector
      total as Duration: Duration()

      default operator ?

      operator |
        -> item as Duration
        total += item

  defines function

    collectAll()
      collector <- DurationCollector()

      //The collector has a '|' for Duration, not for Integer
      cat [PT1H, PT2H, PT3H] >> collector

Fixed: Pipe in the type the collector's '|' takes

#!ek9
defines module error.e07830.good

  defines class

    DurationCollector
      total as Duration: Duration()

      accumulated() as pure
        <- rtn as Duration: total

      operator |
        -> item as Duration
        total += item

      default operator ?

  defines program

    CollectAll()
      stdout <- Stdout()
      collector <- DurationCollector()

      //Duration items into a Duration collector
      cat [P2D, P1W, PT2H] >> collector
      stdout.println($collector.accumulated())

Questions and answers

These Q&A entries show E07830 and its fix:

Found a problem?

If EK9 reported E07830 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.