How to use the fluture.of function in fluture

To help you get started, we’ve selected a few fluture 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 zerobias / telegram-mtproto / packages / telegram-mtproto / src / service / authorizer / index.js View on Github external
if (!bytesCmp(newNonceHash1, response.new_nonce_hash1)) {
    const err = reject(ERR.dh.nonce.hash1())/*::.mapRej(dhAnswerFail)*/
    return err
  }

  const serverSalt = bytesXor(newNonce.slice(0, 8), serverNonce.slice(0, 8))
  // console.log('Auth successfull!', authKeyID, authKey, serverSalt)
  const authBlock = {
    authKeyID : /*:: toCryptoKey(*/ id /*::)*/,
    authKey   : /*:: toCryptoKey(*/ key /*::)*/,
    //eslint-disable-next-line
    serverSalt: /*:: toCryptoKey(*/ serverSalt /*::)*/,
  }

  const result: Fluture = of(authBlock)
  return result
}
github neutrinojs / neutrino / packages / neutrino / src / webpack.js View on Github external
const Future = require('fluture');
const { isEmpty, pathOr, pipe } = require('ramda');
const webpack = require('webpack');
const DevServer = require('webpack-dev-server');
const { toArray } = require('./utils');

// errors :: (Error|Array Error err -> Object stats) -> Array Error
const getErrors = (err, stats) => (err ? toArray(err) : stats.toJson().errors);

// compiler :: Object config -> Future Error Object
const compiler = pipe(Future.of, Future.ap(Future.of(webpack)));

// compile :: Object config -> Future Error Object
const compile = pipe(
  compiler,
  Future.chain(compiler => Future((reject, resolve) => {
    compiler.run((err, stats) => {
      const errors = getErrors(err, stats);

      isEmpty(errors) ? resolve(stats) : reject(errors);
    });
  }))
);

// devServer :: Object config -> Future Error Object
const devServer = pipe(
  compiler,
github arrterian / nix-env-selector / src / actions.ts View on Github external
nixConfigPathTemplate => {
      if (nixConfigPathTemplate === NOT_MODIFIED_ENV) {
        return of(none);
      }

      const nixConfigPath = nixConfigPathTemplate.replace(
        "${workspaceRoot}",
        workspaceRoot
      );

      // NOTE: all sync commands could throw exception
      try {
        return of(
          pipe(
            nixConfigPath,
            getShellCmd("env", nixAttr),
            mapNullable(
              flow(
                // HACK: sync operation using for block tread and prevent loading other
                // extension before environment will be applied
                execSync,
                parseEnv,
                applyEnv
              )
            ),
          )
        );
      } catch (err) {
        return reject(err);
github char0n / monad-t / test / FlutureTMonetEither / index.js View on Github external
it('tests functor (left on Either)', function(done) {
    const add = a => b => a + b;
    const error = new Error();
    const fe = FlutureTMonetEither.of(Future.of(Either.Left(error))).map(add(1));

    fe.fork(
      (val) => {
        assert.strictEqual(val, error);
        done();
      },
      noop
    );
  });
github char0n / monad-t / test / FlutureTMonetEither / index.js View on Github external
it('tests Either.Left in first FTE', function(done) {
      FlutureTMonetEither
        .fromFuture(Future.of('val'))
        .filter(always(false), 'error')
        .and(FlutureTMonetEither.fromEither(Either.Right('val')))
        .fork(
          (val) => {
            assert.strictEqual(val, 'error');
            done();
          },
          noop
        );
    });
github node-gh / gh / src / fp.ts View on Github external
export function safeImport(
    fileName: string
): Future.FutureInstance {
    let moduleObj = null

    try {
        moduleObj = require(fileName)
    } catch (e) {
        return e.code === 'MODULE_NOT_FOUND' ? Future.of(fileName) : Future.reject(e)
    }

    return Future.of(moduleObj)
}
github howtocards / frontend / mock-server / server / commands / user.js View on Github external
export const userRegister = (registerData) => {
  const usersWithEmail = models.Users.chain().find({
    email: registerData.email,
  })

  if (usersWithEmail.count() > 0) {
    return Future.reject("email_already_exists")
  }

  const createdUser = models.Users.insert({
    email: registerData.email,
    password: registerData.password,
  })

  return Future.of({ userId: createdUser.$loki })
}
github node-gh / gh / src / cmd.ts View on Github external
function filterFiles(files: string[]): Future.FutureInstance {
        const alias = files.filter((file: string) => {
            return file.startsWith(name[0]) && file.includes(name[1])
        })[0]

        return alias ? Future.of(alias) : Future.reject(name)
    }
}
github howtocards / frontend / mock-server / server / commands / card.js View on Github external
export function cardsGet() {
  const data = models.Cards.chain()
    .data()
    .map(mapCard)
    .reverse()

  return Future.of(data)
}
github howtocards / frontend / mock-server / server / commands / card.js View on Github external
export async function cardRead(ctx) {
  const data = mapCard(models.Cards.findOne({ $loki: +ctx.params.cardId }))

  return Future.of(data)
}