How to use the fp-ts/lib/Either.right function in fp-ts

To help you get started, we’ve selected a few fp-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 mikearnaldi / matechs-effect / packages / effect / src / stream / support.ts View on Github external
op: Ops,
  callback: (r: E.Either>) => void
): () => void {
  switch (op._tag) {
    case "error":
      callback(E.left(op.e));
      // this will never be called
      /* istanbul ignore next */
      // tslint:disable-next-line: no-empty
      return () => {};
    case "complete":
      callback(E.right(O.none));
      // tslint:disable-next-line: no-empty
      return () => {};
    case "offer":
      callback(E.right(O.some(op.a)));
      // tslint:disable-next-line: no-empty
      return () => {};
  }
}
github gcanti / io-ts-types / test / index.ts View on Github external
it('JSONFromString', () => {
    const T = JSONFromString
    assert.deepEqual(T.decode('{}'), right({}))
    assert.deepEqual(T.decode('[]'), right([]))
    assert.deepEqual(T.decode('"s"'), right('s'))
    assert.deepEqual(T.decode('1'), right(1))
    assert.deepEqual(T.decode('true'), right(true))
    assert.deepEqual(T.decode('null'), right(null))
    assert.deepEqual(T.decode('{"name":"Giulio"}'), right({ name: 'Giulio' }))
    assert.deepEqual(PathReporter.report(T.decode(null)), ['Invalid value null supplied to : JSONFromString'])
    assert.deepEqual(PathReporter.report(T.decode('')), ['Invalid value "" supplied to : JSONFromString'])
  })
})
github gcanti / io-ts-types / test / index.ts View on Github external
it('reverseGet', () => {
      const T = TypePrismIso.reverseGet('NumberFromString', prism, t.number.is)
      assert.deepEqual(T.decode('0'), right(0))
      assert.deepEqual(T.decode('10'), right(10))
      assert.deepEqual(T.decode('-1'), right(-1))
      assert.deepEqual(T.decode('11'), right(11))
      assert.deepEqual(T.decode('5.5'), right(5.5))
      assert.deepEqual(T.decode('-5.5'), right(-5.5))
      assert.deepEqual(PathReporter.report(T.decode('a')), ['Invalid value "a" supplied to : NumberFromString'])
      assert.deepEqual(PathReporter.report(T.decode('2a')), ['Invalid value "2a" supplied to : NumberFromString'])
      assert.deepEqual(PathReporter.report(T.decode('2.a')), ['Invalid value "2.a" supplied to : NumberFromString'])
    })
  })
github paritytech / substrate-light-ui / packages / light-apps / src / AddAccount / ImportWithPhrase.tsx View on Github external
function validate (values: UserInput): Either {
  const errors = {} as UserInputError;

  (['name', 'password', 'recoveryPhrase'] as (keyof UserInput)[])
    .filter((key) => !values[key])
    .forEach((key) => {
      errors[key] = `Field "${key}" cannot be empty`;
    });

  if (values.recoveryPhrase.split(' ').length !== 12) {
    errors.recoveryPhrase = 'Invalid phrase. Please check it and try again.';
  }

  return Object.keys(errors).length ? left(errors) : right(values);
}
github rzeigler / waveguide / src / queue / blocking.ts View on Github external
(waiting) => {
              const [next, queue] = waiting.dequeue();
              if (next) {
                return [next.fill(a), left(queue)];
              }
              return [IO.void(), right(Dequeue.of(a))];
            },
            (available) => [IO.void(), right(available.enqueue(a))]
github rzeigler / waveguide / src / queue.ts View on Github external
poption.map(([next, q]) =>
                                            [makeTicket(io.pure(next), io.unit), right(q) as State<a>] as const),
                    getOrElse(() =&gt; [</a>
github stoplightio / prism / packages / http / src / router / index.ts View on Github external
);
    }

    matches = matches.filter(match => !!match.serverMatch && match.serverMatch !== MatchType.NOMATCH);

    if (!matches.length) {
      return left(
        ProblemJsonError.fromTemplate(
          NO_SERVER_MATCHED_ERROR,
          `The server url ${requestBaseUrl} hasn't been matched with any of the provided servers`
        )
      );
    }
  }

  return right(disambiguateMatches(matches));
};
github teamdigitale / io-functions / lib / utils / azure_storage.ts View on Github external
blobService.getBlobToText(containerName, blobName, (err, result, __) =&gt; {
      if (err) {
        return resolve(left&gt;(err));
      } else {
        return resolve(right&gt;(fromNullable(result)));
      }
    });
  });
github voteflux / THE-APP / packages / api / flux / db / cache.ts View on Github external
return (await promiseToEither(prom)).chain(r =&gt; {
            if (r === null)
                return(left(`Cannot find cached (${namespace}.${key})`))
            return right(r).map(({data}) =&gt; data) as Either
        })
    }