( schema: Schema.Schema<A, I, R> )
| 13 | * @category constructors |
| 14 | */ |
| 15 | export const encode = <A, I, R>( |
| 16 | schema: Schema.Schema<A, I, R> |
| 17 | ) => |
| 18 | <IE = never, Done = unknown>(): Channel.Channel< |
| 19 | Chunk.Chunk<I>, |
| 20 | Chunk.Chunk<A>, |
| 21 | IE | ParseError, |
| 22 | IE, |
| 23 | Done, |
| 24 | Done, |
| 25 | R |
| 26 | > => { |
| 27 | const encode = Schema.encode(Schema.ChunkFromSelf(schema)) |
| 28 | const loop: Channel.Channel<Chunk.Chunk<I>, Chunk.Chunk<A>, IE | ParseError, IE, Done, Done, R> = Channel |
| 29 | .readWithCause({ |
| 30 | onInput: (input: Chunk.Chunk<A>) => |
| 31 | Channel.zipRight( |
| 32 | Channel.flatMap(encode(input), Channel.write), |
| 33 | loop |
| 34 | ), |
| 35 | onFailure: (cause: Cause.Cause<IE>) => Channel.failCause(cause), |
| 36 | onDone: Channel.succeed |
| 37 | }) |
| 38 | return loop |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @since 1.0.0 |
no test coverage detected