How to use the always function from ramda

Find comprehensive JavaScript ramda.always code examples handpicked from public code repositorys.

ramda.always is a function that takes a value and returns a new function that always returns that value regardless of the arguments passed to it.

7
8
9
10
11
12
13
14
15
16
17
18
);


const extractTimeToLive = R.cond([
  [R.propIs(Number, 'expiry'), ({ expiry }) => ttlFromExpiry(expiry)],
  [R.propIs(Number, 'timeToLive'), R.prop('timeToLive')],
  [R.T, R.always(DEFAULT_TTL)],
]);


const pathIsString = R.pathSatisfies(R.is(String));

fork icon117
star icon518
watch icon0

44
45
46
47
48
49
50
51
52
53
// action -> model -> newModel
const update = Action.caseOn({
  ChangeNewTitle: R.assoc('newTitle'),
  Create: (model) => R.evolve({todos: R.append(Todo.init(model.nextId, model.newTitle)),
                               nextId: R.inc,
                               newTitle: R.always('')}, model),
  Remove: (todo, model) => R.evolve({todos: R.reject(R.eq(todo))}, model),
  Modify: (todo, action, model) => {
    const idx = R.indexOf(todo, model.todos)
    return R.evolve({todos: R.adjust(Todo.update(action), idx)}, model)
fork icon92
star icon0
watch icon2

+ 3 other calls in file

How does ramda.always work?

ramda.always is a higher-order function that takes a value and returns a new function that always returns that value, regardless of its arguments.

161
162
163
164
165
166
167
168
169
170
      },
      Get: function(key, f) {
        return interpretPure(f(store[key]), store);
      }
    });
  }, R.always(store));
}

var script = get('swiss bank account id').chain(function(id) {
  return modify(id, R.add(1000000))
fork icon1
star icon5
watch icon4

+ 15 other calls in file

25
26
27
28
29
30
31
32
33
34
  R.pick(['user', 'header'])
);

const coerceToArray = R.cond([
  [R.is(String), v => [v]],
  [R.isNil, R.always([])],
  [R.T, R.identity],
]);

function coerceToBoolean(value) {
fork icon303
star icon0
watch icon2

+ 9 other calls in file

Ai Example

1
2
3
4
const R = require("ramda");

const always42 = R.always(42);
console.log(always42()); // output: 42

In the above example, ramda.always is used to create a new function called always42 that always returns the value 42 when it's called, regardless of the arguments passed to it.

44
45
46
47
48
49
50
51
52
53
const viewCounter = R.curry((actions$, c) => {
  const [id, model] = c;
  console.log('viewCounter', id, model);
  return counter.viewWithRemoveButton({
    actions$: forwardTo(actions$, Action.Modify(id)),
    remove$: forwardTo(actions$, R.always(Action.Remove(id))),
  }, model);
});

const view = R.curry((actions$, model) => {
fork icon91
star icon0
watch icon2

+ 9 other calls in file

153
154
155
156
157
158
159
160
161
162
163
164


// R.cond is like a switch statement
const calculateNextReviewDate = R.cond([
  [R.equals('6'), () => moment().add(6, 'months').format('DD/MM/YYYY')],
  [R.equals('12'), () => moment().add(1, 'years').format('DD/MM/YYYY')],
  [R.T, R.always('')],
])


const catMap = new Set(['DB', 'DC', 'DI', 'CB', 'JI', 'JC', 'JB', 'JD', 'JT', 'JR', 'TR', 'TI'])
const choosingHigherCategory = (current, newCat) => catMap.has(current + newCat)
fork icon3
star icon4
watch icon0

16
17
18
19
20
21
22
23
24
25

var __ = _require2.__;
var liftN = _require2.liftN;
var curry = _require2.curry;
var pipe = _require2.pipe;
var always = _require2.always;
var merge = _require2.merge;
var props = _require2.props;
var apply = _require2.apply;
var identity = _require2.identity;
fork icon1
star icon3
watch icon3

23
24
25
26
27
28
29
30
31
32
33
34
console.log('alwaysTrue=', alwaysTrue(1, 'Two'))




const fn = _.cond([
    [_.equals(0), _.always('water freezes at 0°C')],
    [_.equals(100), _.always('water boils at 100°C')],
    [_.T, temp => 'nothing special happens at ' + temp + '°C']
])
fn(0) //=> 'water freezes at 0°C'
fn(50) //=> 'nothing special happens at 50°C'
fork icon1
star icon2
watch icon0

+ 3 other calls in file

80
81
82
83
84
85
86
87
88
89
90
91
};


var getUnusedPricesFromSearchMemory = function getUnusedPricesFromSearchMemory(queryID) {
  return R.call(R.ifElse(Boolean, function (memory) {
    return memory.getValues().unusedPrices;
  }, R.always([])), _resultsMemory.memoryInstances[queryID]);
};


var getUnusedHotelsFromSearchMemory = function getUnusedHotelsFromSearchMemory(queryID) {
  return R.call(R.pipe(getUnusedPricesFromSearchMemory, R.map(R.prop('hotelID'))), queryID);
fork icon0
star icon3
watch icon4

+ 167 other calls in file

617
618
619
620
621
622
623
624
625
626
627
628
629


const withFallback = (obj, platform) => obj[platform] || obj["default"];


function createManifest({ version, platform }) {
  const basePlatform = R.cond([
    [isApple, R.always("apple")],
    [iAndroid, R.always("android")],
  ])(platform);


  return {
fork icon0
star icon3
watch icon0

3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595


function createManifest({ version, platform }) {
  const basePlatform = R.cond([
    [isApple, R.always("apple")],
    [iAndroid, R.always("android")],
    [isWeb, R.always("web")],
  ])(platform);


  const isTV = R.includes(platform, tvPlatforms);
  return {
fork icon0
star icon3
watch icon0

+ 2 other calls in file

100
101
102
103
104
105
106
107
108
109
110
  }, function (geo, key) {
    return R.call(R.pipe(function (operators) {
      return operators.toObject();
    }, R.prop(key), R.ifElse(Boolean, function (operators) {
      return operators.toArray();
    }, R.always(EMPTY_ARRAY))), geo.get('operators'));
  });
};


exports.getOperators = getOperators;
fork icon0
star icon3
watch icon0

19
20
21
22
23
24
25
26
27
		retain: R.dec,
	}
})
const refreshContext = R.evolve({
	[cur_name]: {
		retain: R.always(max_retain),
	}
})
const purge = R.dissoc(cur_name)
fork icon1
star icon0
watch icon0

17
18
19
20
21
22
23
24
25
26
27
28


const STORYBOOK_BUILD_DIR = path.resolve(__dirname, '../', storybookBuildDir);
const STORYBOOK_IFRAME = path.join(STORYBOOK_BUILD_DIR, 'iframe.html');


const severityToColor = R.cond([
  [R.equals('error'), R.always('red')],
  [R.equals('warning'), R.always('yellow')],
  [R.equals('notice'), R.always('blue')],
]);

fork icon0
star icon2
watch icon0

+ 2 other calls in file

10
11
12
13
14
15
16
17
18
19
const dir = command.slice(3)

return R.modify(
  'cwd',
  dir === '/'
    ? R.always([])
    : dir === '..'
    ? R.slice(0, -1)
    : R.append(dir),
  state,
fork icon0
star icon1
watch icon0

208
209
210
211
212
213
214
215
216
217
};
var stream = xstream_1.default.create(producer);
var adaptedStream = this.runSA.adapt(stream, xstream_adapter_1.default.streamSubscribe);
adaptedStream.id = id;
adaptedStream.play = R.always({ id: id, cmd: 'play' });
adaptedStream.pause = R.always({ id: id, cmd: 'pause' });
adaptedStream.setCurrentTime = function (data) { return ({ id: id, cmd: 'setCurrentTime', data: data }); };
adaptedStream.setLoop = function (data) { return ({ id: id, cmd: 'setLoop', data: data }); };
adaptedStream.setMuted = function (data) { return ({ id: id, cmd: 'setMuted', data: data }); };
adaptedStream.setPlaybackRate = function (data) { return ({ id: id, cmd: 'setPlaybackRate', data: data }); };
fork icon0
star icon0
watch icon2

+ 89 other calls in file

28
29
30
31
32
33
34
35
36
37
38
39
var warn = logWithPrefix('\u001b[33m>>> WARNING: \u001b[39;49m');


//  abort :: String -> !
var abort = R.pipe(
  logWithPrefix('\u001b[31m>>> ERROR: \u001b[39;49m'),
  R.always(1),
  process.exit
);


//  filenameToIdentifier :: String -> String
fork icon0
star icon0
watch icon0

10
11
12
13
14
15
16
17
18
19
20
21
const serialize = R.unary(JSON.stringify);
const deserialize = R.unary(JSON.parse);


const deserializeCacheValue = R.ifElse(
  R.not,
  R.always([]),
  deserialize
);


const getFromCache = (cache, CACHE_KEY) => (
fork icon0
star icon0
watch icon0

118
119
120
121
122
123
124
125
126
127

const getHosts = () =>
  Promise.all([fetchZoneRecords(), fetchRedirections()]).then(R.flatten);

const addRecords = R.compose(batchLazyTasks(BATCH_SIZE), R.filter(Boolean), R.map(R.cond([
  [R.propEq('name', 'www'), R.always(null)], // Ignore www
  [R.propEq('type', 'URL'), addRedirection],
  [R.T, addZoneRecord],
])));
const removeRecords = R.compose(batchLazyTasks(BATCH_SIZE), R.map(R.cond([
fork icon0
star icon0
watch icon0

487
488
489
490
491
492
493
494
495
* @sig a -> (* -> a)
* @param {*} val The value to wrap in a function
* @return {Function} A Function :: * -> val.
* @example
*
*      const t = R.always('Tee');
*      t(); //=> 'Tee'
*/

fork icon0
star icon0
watch icon2

+ 11 other calls in file

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)