How to use the parser-ts.string.fold function in parser-ts

To help you get started, we’ve selected a few parser-ts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gcanti / fp-ts-codegen / src / haskell.ts View on Github external
* @since 0.4.0
 */
export const constructor: P.Parser = pipe(
  recordConstructor,
  P.alt(() => positionalConstructor)
)

const equal = S.fold([S.spaces, C.char('='), S.spaces])

const unconstrainedParameterDeclaration: P.Parser = pipe(
  identifier,
  P.map(name => M.parameterDeclaration(name))
)

const constrainedParameterDeclaration: P.Parser = pipe(
  S.fold([C.char('('), S.spaces]),
  P.apSecond(
    pipe(
      pair,
      P.map(({ name, type }) => M.parameterDeclaration(name, some(type))),
      P.apFirst(S.fold([S.spaces, C.char(')')]))
    )
  )
)

export const parameterDeclaration = P.expected(
  pipe(
    unconstrainedParameterDeclaration,
    P.alt(() => constrainedParameterDeclaration)
  ),
  'a parameter'
)