@ldflex/async-iteration-handlers
This library acts as a wrapper for functions from the async library, exporting them as handlers to be used by LDflex.

All exported handlers (defaultIterationHandlers
)
Initialization
const { PathFactory, defaultHandlers } = require('ldflex');
const { default: ComunicaEngine } = require('@ldflex/comunica');
const { default: defaultIterationHandlers } = require('@ldflex/async-iteration-handlers');
const { namedNode } = require('@rdfjs/data-model');
const context = {
"@context": {
"@vocab": "http://xmlns.com/foaf/0.1/",
"friends": "knows",
"label": "http://www.w3.org/2000/01/rdf-schema#label",
}
};
const queryEngine = new ComunicaEngine('https://ruben.verborgh.org/profile/');
const path = new PathFactory({
context,
queryEngine,
handlers: {
...defaultHandlers,
...defaultIterationHandlers
}
});
const ruben = path.create({ subject: namedNode('https://ruben.verborgh.org/profile/#me') });
ruben.friends.forEach(async (x: any) => {
console.log(`${await x}`)
});
Available Methods
.every
.everyLimit
.everySeries
const allFriendsLabelled: Promise<boolean> = path.friends.every(
async friend => `${await friend.label}` !== 'undefined'
);
const allFriendsLabelled: Promise<boolean> = path.friends.everySeries(
async friend => `${await friend.label}` !== 'undefined'
);
const allFriendsLabelled: Promise<boolean> = path.friends.everyLimit(
async friend => `${await friend.label}` !== 'undefined',
5
);
.filter
.filterLimit
.filterSeries
const labelledFriends: Promise<string[]> = path.friends.filter(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriends: Promise<string[]> = path.friends.filterSeries(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriends: Promise<string[]> = path.friends.filterLimit(
async friend => `${await friend.label}` !== 'undefined',
5
);
.find
.findLimit
.findSeries
const labelledFriend: Promise<string> = path.friends.find(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriend: Promise<string> = path.friends.findSeries(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriend: Promise<string> = path.friends.findLimit(
async friend => `${await friend.label}` !== 'undefined',
5
);
.forEach
.forEachLimit
.forEachSeries
const labelledFriend = [];
path.friends.forEach(
async friend => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
}
);
path.friends.forEachSeries(
async friend => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
}
);
path.friends.forEachLimit(
async friend => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
},
5
);
.forEachOf
.forEachOfLimit
.forEachOfSeries
const labelledFriend = [];
path.friends.forEachOf(
async (friend, index) => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
}
);
path.friends.forEachOfSeries(
async (friend, index) => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
}
);
path.friends.forEachOfLimit(
async (friend, index) => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
},
5
);
.map
.mapLimit
.mapSeries
const friendLabels: Promise<string[]> = path.friends.map(
async friend => `${await friend.label}`
);
const friendLabels: Promise<string[]> = path.friends.mapSeries(
async friend => `${await friend.label}`
);
const friendLabels: Promise<string[]> = path.friends.mapLimit(
async friend => `${await friend.label}`,
5
);
.some
.someLimit
.someSeries
const someFriendsLabelled: Promise<boolean> = path.friends.some(
friend => `${friend.label}` !== 'undefined'
);
const someFriendsLabelled: Promise<boolean> = path.friends.someLimit(
friend => `${friend.label}` !== 'undefined'
);
const someFriendsLabelled: Promise<boolean> = path.friends.someSeries(
friend => `${friend.label}` !== 'undefined',
5
);
const friendLabels: Promise<string>= path.friends.reduce(
async (total, friend) => `${total}&${await friend.label}`,
''
);
Alternatively if you wish to only use sychronous handlers (seriesIterationHandlers
)
Initialization
const { PathFactory } = require('ldflex');
const { default: ComunicaEngine, defaultHandlers } = require('@ldflex/comunica');
const { seriesIterationHandlers } = require('@ldflex/async-iteration-handlers');
const { namedNode } = require('@rdfjs/data-model');
const context = {
"@context": {
"@vocab": "http://xmlns.com/foaf/0.1/",
"friends": "knows",
"label": "http://www.w3.org/2000/01/rdf-schema#label",
}
};
const queryEngine = new ComunicaEngine('https://ruben.verborgh.org/profile/');
const path = new PathFactory({
context,
queryEngine,
handlers: [
...defaultHandlers,
...seriesIterationHandlers
]
});
Available Methods
const allFriendsLabelled: Promise<boolean> = path.friends.every(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriends: Promise<string[]> = path.friends.filter(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriend: Promise<string> = path.friends.find(
async friend => `${await friend.label}` !== 'undefined'
);
const labelledFriend = [];
path.friends.forEach(
async friend => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
}
);
const labelledFriend = [];
path.friends.forEachOf(
async (friend, index) => {
if (`${await friend.label}` !== 'undefined') {
labelledFriend.push(friend)
}
}
);
const friendLabels: Promise<string[]> = path.friends.map(
async friend => `${await friend.label}`
);
const someFriendsLabelled: Promise<boolean> = path.friends.some(
friend => `${friend.label}` !== 'undefined'
);
const friendLabels: Promise<string>= path.friends.reduce(
async (total, friend) => `${total}&${await friend.label}`,
''
);
NOTE
By default, methods with limited asynchronicity process at most 5 entities concurrently.
License
©2020–present
Jesse Wright,
Ruben Verborgh,
Ruben Taelman.
MIT License.