cats | REST API Fuzzer and negative testing tool
kandi X-RAY | cats Summary
Support
Quality
Security
License
Reuse
- Performs a custom test
- Check verify parameters and report result
- Sets the output variables
- Gets the value of the property in body
- Start the downloader
- Downloads a file from the given URL
- Runs the test case
- Check for missing fields
- Processes the fuzzing data
- Checks if the field value matches the fuzzy pattern
- Fuzzify the headers
- Performs a subset of the given fields and checks if required
- Performs the actual fuzzing
- Checks if the current path contains versioning information
- Runs the catcher
- Gets the fuzzing strategy
- Run test case
- Adds references to a schema
- Generate value
- fuzzing the given path
- Checks if the current path contains the required tags
- Parses the given SPEL expression
- Intercepts method invocation
- Do fuzzing
- Generates the boundary value
- Process the fuzzing data
cats Key Features
cats Examples and Code Snippets
Trending Discussions on cats
Trending Discussions on cats
QUESTION
I'm defining a type whose type parameters have some relations. I have Item
type which takes Cat
and SubCat
, but you can use some of the types of SubCat
depending on Cat
. For example, when you specify Cat1
as Cat
, you can specify SubCat1
or SubCat2
as SubCat
.
I implemented it using ValidSubCats
type family to define valid SubCat
s for each Cat
, and OneOf
type family to define a constraint.
{-# LANGUAGE DataKinds, GADTs, PolyKinds, StandaloneKindSignatures, TypeFamilies, TypeOperators #-}
import Data.Kind (Constraint, Type)
import Data.Type.Equality ((:~:)(..), TestEquality(..))
import Unsafe.Coerce (unsafeCoerce)
data Cat = Cat1 | Cat2
type SCat :: Cat -> Type
data SCat cat where
SCat1 :: SCat 'Cat1
SCat2 :: SCat 'Cat2
data SubCat = SubCat1 | SubCat2 | SubCat3
type SSubCat :: SubCat -> Type
data SSubCat subCat where
SSubCat1 :: SSubCat 'SubCat1
SSubCat2 :: SSubCat 'SubCat2
SSubCat3 :: SSubCat 'SubCat3
type ValidSubCats :: Cat -> [SubCat]
type family ValidSubCats cat where
ValidSubCats 'Cat1 = '[ 'SubCat1, 'SubCat2 ]
ValidSubCats 'Cat2 = '[ 'SubCat2, 'SubCat3 ]
type OneOf :: k -> [k] -> Constraint
type family OneOf t ts where
OneOf t (t ': _) = ()
OneOf t (_ ': ts) = OneOf t ts
OneOf _ _ = ('True ~ 'False)
type Item :: Cat -> SubCat -> Type
data Item cat subCat where
Item :: OneOf subCat (ValidSubCats cat) => Item cat subCat
Now, I'm trying to define a function to create an Item
from SCat
and SSubCat
.
type HL :: (k -> Type) -> [k] -> Type
data HL f t where
HCons :: f t -> HL f ts -> HL f (t ': ts)
HNil :: HL f '[]
infixr 5 `HCons`
validSSubCats :: SCat cat -> HL SSubCat (ValidSubCats cat)
validSSubCats SCat1 = SSubCat1 `HCons` SSubCat2 `HCons` HNil
validSSubCats SCat2 = SSubCat2 `HCons` SSubCat3 `HCons` HNil
instance TestEquality SSubCat where
testEquality SSubCat1 SSubCat1 = Just Refl
testEquality SSubCat2 SSubCat2 = Just Refl
testEquality SSubCat3 SSubCat3 = Just Refl
testEquality _ _ = Nothing
oneOf :: TestEquality f => f t -> HL f ts -> Maybe (OneOf t ts :~: (() :: Constraint))
oneOf x (HCons y ys) = case testEquality x y of
Just Refl -> Just Refl
Nothing -> unsafeCoerce $ oneOf x ys
oneOf _ HNil = Nothing
makeItem :: SCat cat -> SSubCat subCat -> Maybe (Item cat subCat)
makeItem sCat sSubCat = case oneOf sSubCat (validSSubCats sCat) of
Just Refl -> Just Item
Nothing -> Nothing
But as you can see, I'm using unsafeCoerce
to define oneOf
. I got this error when I removed it.
test.hs:54:39: error:
• Could not deduce: OneOf t ts1 ~ OneOf t (t1 : ts1)
from the context: ts ~ (t1 : ts1)
bound by a pattern with constructor:
HCons :: forall {k} (f :: k -> *) (t :: k) (ts :: [k]).
f t -> HL f ts -> HL f (t : ts),
in an equation for ‘oneOf’
at q.hs:52:10-19
Expected: Maybe (OneOf t ts :~: (() :: Constraint))
Actual: Maybe (OneOf t ts1 :~: (() :: Constraint))
NB: ‘OneOf’ is a non-injective type family
• In the expression: oneOf x ys
In a case alternative: Nothing -> oneOf x ys
In the expression:
case testEquality x y of
Just Refl -> Just Refl
Nothing -> oneOf x ys
• Relevant bindings include
ys :: HL f ts1 (bound at q.hs:52:18)
y :: f t1 (bound at q.hs:52:16)
x :: f t (bound at q.hs:52:7)
oneOf :: f t
-> HL f ts -> Maybe (OneOf t ts :~: (() :: Constraint))
(bound at q.hs:52:1)
|
54 | Nothing -> oneOf x ys
| ^^^^^^^^^^
How can I convince GHC that it can infer OneOf t (t ': ts) :~: (() :: Constraint)
from OneOf t ts :~: (() :: Constraint)
without using unsafeCoerce
?
ANSWER
Answered 2022-Apr-10 at 18:45I would suggest using something which has a value-level representation, since we can directly manipulate such things more easily. This is often easier to work with in general. For example:
data OneOf' t ts where
Here :: forall t ts. OneOf' t (t ': ts)
There :: forall t t2 ts. OneOf' t ts -> OneOf' t (t2 ': ts)
oneOf' :: TestEquality f => f t -> HL f ts -> Maybe (OneOf' t ts)
oneOf' _ HNil = Nothing
oneOf' x (HCons y ys) =
case testEquality x y of
Just Refl -> Just Here
Nothing -> There <$> oneOf' x ys
This does not directly answer the question as asked, although if you can write a function with type
convertOneOf :: forall t ts. OneOf' t ts -> (OneOf t ts :~: (() :: Constraint))
then it would answer the exact question. Right now, I'm not sure how to do this (or even whether it is possible). I think you need an auxiliary function
weakenOneOf :: forall t t2 ts. OneOfTrue t ts -> OneOfTrue t (t2 ': ts)
(where I've used the synonym OneOfTrue
to make things easier to read: type OneOfTrue t ts = OneOf t ts :~: (() :: Constraint)
).
If this can be implemented then you should be good to go, although I would probably still prefer to use OneOf'
when possible.
It's worth noting that something like OneOf'
is a relatively common construct in dependently typed languages: There's an Agda example here, an Idris example here and a similar thing in Coq here. Each of these has value-level content in the same way that OneOf'
does.
Item
could be rewritten to use OneOf'
like this:
type Item' :: Cat -> SubCat -> Type
data Item' cat subCat where
Item' :: OneOf' subCat (ValidSubCats cat) -> Item' cat subCat
and there is a corresponding rewrite for makeItem
to use Item'
.
OneOf
is tricky and OneOf'
is less tricky
It is often difficult to work with something like OneOf
. One reason is that Haskell allows type families which can get "stuck". This prevents can prevent some type-level "reductions" and we do not have things like canonical forms.
For example, consider this definition which could be useful in dealing with something like type-level lists passed to a OneOf
:
listDecideNilCons :: forall ts. Either (ts :~: '[]) (IsCons ts)
listDecideNilCons = ...
data IsCons a where
MkIsCons :: forall t ts. IsCons (t ': ts)
listDecideNilCons
would just tell you that a type-level list is either a nil or a cons, which seems pretty reasonable and it would be a handy fact to make use of. In fact, I suspect that it would be necessary to be able to implement listDecideNilCons
or something similar to it in order to be able to implement convertOneOf
. I suspect even more strongly that it is necessary to implement the other direction of the conversion.
However, the existence of stuck type families is sufficient to show that listDecideNilCons
cannot be implemented. Consider:
type family Sticky (b :: Bool) :: [Int] where
Sticky True = '[]
example :: Either ((Sticky False) :~: '[]) (IsCons (Sticky False))
example = listDecideNilCons
This code type-checks. What should the value of example
be? Since Sticky False
cannot be reduced any further, there isn't a value for example
that would make sense.
Note that if we also have value-level information, like we do with OneOf'
, we do not run into this issue for two reasons: Stuck types are not an issue because we can control which specific "shapes" (like '[]
and ... ': ...
) we are allowed to take in and we can use the proof values when we construct proofs of new things.
For example, in the case of OneOf'
, it ensures that the type-level list will have the "shape" ... ': ...
. In the function oneOf'
, we are using the proof value from the recursive call oneOf' x ys
to build a larger proof.
In the original oneOf
function, we cannot make use of the fact that the result of a recursive call will either have a "cons shape" or it will give back Nothing
(since the original OneOf
doesn't give us this information). However, we must know this to use the result of the recursive call to produce the desired result since the original OneOf
requires a "cons shape".
QUESTION
I've the following table
Owner Pet Housing_Type A Cats;Dog;Rabbit 3 B Dog;Rabbit 2 C Cats 2 D Cats;Rabbit 3 E Cats;Fish 1The code is as follows:
Data_Pets = structure(list(Owner = structure(1:5, .Label = c("A", "B", "C", "D",
"E"), class = "factor"), Pets = structure(c(2L, 5L, 1L,4L, 3L), .Label = c("Cats ",
"Cats;Dog;Rabbit", "Cats;Fish","Cats;Rabbit", "Dog;Rabbit"), class = "factor"),
House_Type = c(3L,2L, 2L, 3L, 1L)), class = "data.frame", row.names = c(NA, -5L))
Can anyone advise me how I can create new columns based on the data in Pet column by creating a new column for each animal separated by ; to look like the following table?
Owner Cats Dog Rabbit Fish Housing_Type A Y Y Y N 3 B N Y Y N 2 C N Y N N 2 D Y N Y N 3 E Y N N Y 1Thanks!
ANSWER
Answered 2022-Mar-15 at 08:48One approach is to define a helper function that matches for a specific animal, then bind the columns to the original frame.
Note that some wrangling is done to get rid of whitespace to identify the unique animals to query.
f <- Vectorize(function(string, match) {
ifelse(grepl(match, string), "Y", "N")
}, c("match"))
df %>%
bind_cols(
f(df$Pets, unique(unlist(strsplit(trimws(as.character(df$Pets)), ";"))))
)
Owner Pets House_Type Cats Dog Rabbit Fish
1 A Cats;Dog;Rabbit 3 Y Y Y N
2 B Dog;Rabbit 2 N Y Y N
3 C Cats 2 Y N N N
4 D Cats;Rabbit 3 Y N Y N
5 E Cats;Fish 1 Y N N Y
Or more generalized if you don't know for sure that the separator is ;
, and whitespace is present, stringi
is useful:
dplyr::bind_cols(
df,
f(df$Pets, unique(unlist(stringi::stri_extract_all_words(df$Pets))))
)
QUESTION
I am trying to migrate project from cats-effect 2 to cats-effect 3, i am using doobie for interacting with database. Previously i could lift ConnectionIO
to IO
as it was described, but with the upgrade i didn't find any implementation of LiftIO[ConnectionIO]
, how can be same achieved with CE3?
ANSWER
Answered 2022-Feb-21 at 20:03I found the way to achieve it by
def f()(implicit liftToConnectionIO: FunctionK[IO, ConnectionIO]): IO[Unit] = IO.unit
implicit val liftToConnectionIO = WeakAsync.liftK[IO, ConnectionIO]
liftToConnectionIO.use(implicit lift => f())
QUESTION
I have a nested list of lists which contains some data frames. However, the data frames can appear at any level in the list. What I want to end up with is a flat list, i.e. just one level, where each element is only the data frames, with all other things discarded.
I have come up with a solution for this, but it looks very clunky and I am sure there ought to be a more elegant solution.
Importantly, I'm looking for something in base R, that can extract data frames at any level inside the nested list. I have tried unlist()
and dabbled with rapply()
but somehow not found a satisfying solution.
Example code follows: an example list, what I am actually trying to achieve, and my own solution which I am not very happy with. Thanks for any help!
# extract dfs from list
# example of multi-level list with some dfs in it
# note, dfs could be nested at any level
problem1 <- list(x1 = 1,
x2 = list(
x3 = "dog",
x4 = data.frame(cats = c(1, 2),
pigs = c(3, 4))
),
x5 = data.frame(sheep = c(1,2,3),
goats = c(4,5,6)),
x6 = list(a = 2,
b = "c"),
x7 = head(cars,5))
# want to end up with flat list like this (names format is optional)
result1 <- list(x2.x4 = data.frame(cats = c(1, 2),
pigs = c(3, 4)),
x5 = data.frame(sheep = c(1,2,3),
goats = c(4,5,6)),
x7 = head(cars,5))
# my solution (not very satisfactory)
exit_loop <- FALSE
while(exit_loop == FALSE){
# find dfs (logical)
idfs <- sapply(problem1, is.data.frame)
# check if all data frames
exit_loop <- all(idfs)
# remove anything not df or list
problem1 <- problem1[idfs | sapply(problem1, is.list)]
# find dfs again (logical)
idfs <- sapply(problem1, is.data.frame)
# unlist only the non-df part
problem1 <- c(problem1[idfs], unlist(problem1[!idfs], recursive = FALSE))
}
ANSWER
Answered 2021-Dec-28 at 22:13Maybe consider a simple recursive function like this
find_df <- function(x) {
if (is.data.frame(x))
return(list(x))
if (!is.list(x))
return(NULL)
unlist(lapply(x, find_df), FALSE)
}
Results
> find_df(problem1)
$x2.x4
cats pigs
1 1 3
2 2 4
$x5
sheep goats
1 1 4
2 2 5
3 3 6
$x7
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
QUESTION
I'm having some trouble using method resolution clause in Delphi 10.4.
Say I want to create a cat and a dog repository. In this case the TAnimalRepository has both cats and dogs, so I would like to implement both the cat and dog interfaces in that class.
Example:
IRepositoryBase = Interface
['{776B3383-AF6E-44F7-BF32-1ACCF9A6C964}']
function GetAll(items: TList; out errMsg: String): Boolean;
End;
TCat = class
end;
ICatRepository = Interface(IRepositoryBase)
['{C37CF989-E069-450B-8937-E46F6BFA66E9}']
function GetAll(items: TList; out errMsg: String): Boolean;
End;
TDog = class
end;
IDogRepository = Interface(IRepositoryBase)
['{56B28463-0007-497E-8015-D794873328FF}']
function GetAll(items: TList; out errMsg: String): Boolean;
End;
TAnimalRepository = class(TInterfacedObject, ICatRepository, IDogRepository)
function ICatRepository.GetAll = GetAllCats;
function IDogRepository.GetAll = GetAllDogs;
public
function GetAllCats(items: TList; out errMsg: String): Boolean;
function GetAllDogs(items: TList; out errMsg: String): Boolean;
end;
Since we have two different methods with the same name, I have tried to use method resolution clause as described here: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Implementing_Interfaces
function ICatRepository.GetAll = GetAllCats;
function IDogRepository.GetAll = GetAllDogs;
But when I try to compile the above code, it fails with:
[dcc32 Error] MethodResolutionExample.dpr(33): E2291 Missing implementation of interface method MethodResolutionExample.IRepositoryBase.GetAll
[dcc32 Error] MethodResolutionExample.dpr(33): E2291 Missing implementation of interface method MethodResolutionExample.IRepositoryBase.GetAll
Then I thought, why not try to add a method resolution for their inherited interface IRepositoryBase as well, like this:
TAnimalRepository = class(TInterfacedObject, ICatRepository, IDogRepository)
function ICatRepository.GetAll = GetAllCats;
function IRepositoryBase.GetAll = GetAllCats; // <--- This
function IDogRepository.GetAll = GetAllDogs;
function IRepositoryBase.GetAll = GetAllDogs; // <--- This
public
function GetAllCats(items: TList; out errMsg: String): Boolean;
function GetAllDogs(items: TList; out errMsg: String): Boolean;
end;
But now it gets funky. It looks like the compiler can't handle generics in the method resolution clause, because I get a lot of parsing errors now, beginning with:
[dcc32 Error] MethodResolutionExample.dpr(35): E2023 Function needs result type
It complains about this line:
function IRepositoryBase.GetAll = GetAllCats;
What am I doing wrong? Do I really have to split my TAnimalRepository up in two different classes?
Thanks in advance.
Oh, one important note. I can get it to work, if my ICatRepository and IDogRepository doesn't inherit from IRepositoryBase. But in my use case, I would like them to inherit from the base class.
ANSWER
Answered 2021-Dec-21 at 14:53You need to get rid of the additional declarations of GetAll in ICatRepository and IDogRepository. If you just leave the GUID in these interfaces all works as expected.
type
IRepositoryBase = interface
['{776B3383-AF6E-44F7-BF32-1ACCF9A6C964}']
function GetAll(items: TList; out errMsg: string): Boolean;
end;
TCat = class
end;
ICatRepository = interface(IRepositoryBase)
['{C37CF989-E069-450B-8937-E46F6BFA66E9}']
end;
TDog = class
end;
IDogRepository = interface(IRepositoryBase)
['{56B28463-0007-497E-8015-D794873328FF}']
end;
TAnimalRepository = class(TInterfacedObject, ICatRepository, IDogRepository)
function ICatRepository.GetAll = GetAllCats;
function IDogRepository.GetAll = GetAllDogs;
public
function GetAllCats(items: TList; out errMsg: string): Boolean;
function GetAllDogs(items: TList; out errMsg: string): Boolean;
end;
The additional GetAll declarations don't just replace the generic one, but add another method to the interface instead.
QUESTION
I want to replace NA values with the mean of other column with the same year.
Note:
To replace NA values for Canada data, I want to use only the mean of Canada, not the mean from the whole dataset of course.
Here's a sample dataframe filled with random numbers. And some NA how i find them in my dataframe:
Country Inhabitants Year Area Cats Dogs Canada 38 000 000 2021 4 32 21 Canada 37 000 000 2020 4 NA 21 Canada 36 000 000 2019 3 32 21 Canada NA 2018 2 32 21 Canada 34 000 000 2017 NA 32 21 Canada 35 000 000 2016 3 32 NA Brazil 212 000 000 2021 5 32 21 Brazil 211 000 000 2020 4 NA 21 Brazil 210 000 000 2019 NA 32 21 Brazil 209 000 000 2018 4 32 21 Brazil NA 2017 2 32 21 Brazil 207 000 000 2016 4 32 NAWhat's the easiest way with pandas to replace those NA with the mean values of the other years? And is it possible to write a code for which it is possible to go through every NA and replace them (Inhabitants, Area, Cats, Dogs at once)?
ANSWER
Answered 2021-Dec-12 at 15:07Note Example is based on your additional data source from the comments
Replacing the NA-Values for multiple columns with mean()
you can combine the following three methods:
df = pd.read_excel('https://happiness-report.s3.amazonaws.com/2021/DataPanelWHR2021C2.xls')
fillna()
and iterate over all columns grouped by name of country:
df = df.fillna(df.groupby('Country name').transform('mean'))
df[df['Country name'] == 'Canada']
QUESTION
Most examples I've seen of how to test a Prisma-injected NestJS Service (e.g. prisma-sample
in testing-nestjs
) are for "end to end" testing. They actually access the database, performing actual queries and then rolling back the results if necessary.
For my current needs, I want to implement lower-level "integration" testing.
As part of this, I want to remove Prisma from the equation. I want the focus to be on my service's functionality instead of the state of data within the database and Prisma's ability to return it.
One big win of this approach is that it obviates the need to craft "setup" queries and "teardown"/reset operations for specific tests. Instead, I'd like to simply manually specify what we would expect Prisma to return.
In an environment consisting of NestJS, Prisma, and Jest, how should I accomplish this?
UPDATE: The author of the testing-nestjs project pointed out in the comments that the project does have an example of database mocking. It looks nice! Others may still be interested in checking out the Gist that I've linked to as it includes some other useful functionality.
ANSWER
Answered 2021-Dec-04 at 19:40To get a reference to your service's prisma instance, use:
prisma = module.get(PrismaService)
Then, assuming your function calls prisma.name.findMany()
, you can use jest.fn().mockReturnValueOnce()
to mock (manually specify) Prisma's next return value:
prisma.name.findMany = jest.fn().mockReturnValueOnce([
{ id: 0, name: 'developer' },
{ id: 10, name: 'architect' },
{ id: 13, name: 'dog walker' }
]);
(Of course, you would change prisma.name.findMany
in the code above to match whatever function you're calling.)
Then, call the function on your Service that you're testing. For example:
expect(await service.getFirstJob("steve")).toBe('developer');
That's it! A full code example can be found here.
QUESTION
I have been trying to draw border of an Image with transparent background using OpenGL in Android. I am using Fragment Shader & Vertex Shader. (From the GPUImage Library)
Below I have added Fig. A & Fig B.
Fig A.
Fig B.
I have achieved Fig A. With the customised Fragment Shader. But Unable to make the border smoother as in Fig B. I am attaching the Shader code that I have used (to achieve rough border). Can someone here help me on how to make the border smoother?
Here is my Vertex Shader :
attribute vec4 position;
attribute vec4 inputTextureCoordinate;
varying vec2 textureCoordinate;
void main()
{
gl_Position = position;
textureCoordinate = inputTextureCoordinate.xy;
}
Here is my Fragment Shader :
I have calculated 8 pixels around the current pixel. If any one pixel of those 8 is opaque(having alpha greater than 0.4), It it drawn as a border color.
precision mediump float;
uniform sampler2D inputImageTexture;
varying vec2 textureCoordinate;
uniform lowp float thickness;
uniform lowp vec4 color;
void main() {
float x = textureCoordinate.x;
float y = textureCoordinate.y;
vec4 current = texture2D(inputImageTexture, vec2(x,y));
if ( current.a != 1.0 ) {
float offset = thickness * 0.5;
vec4 top = texture2D(inputImageTexture, vec2(x, y - offset));
vec4 topRight = texture2D(inputImageTexture, vec2(x + offset,y - offset));
vec4 topLeft = texture2D(inputImageTexture, vec2(x - offset, y - offset));
vec4 right = texture2D(inputImageTexture, vec2(x + offset, y ));
vec4 bottom = texture2D(inputImageTexture, vec2(x , y + offset));
vec4 bottomLeft = texture2D(inputImageTexture, vec2(x - offset, y + offset));
vec4 bottomRight = texture2D(inputImageTexture, vec2(x + offset, y + offset));
vec4 left = texture2D(inputImageTexture, vec2(x - offset, y ));
if ( top.a > 0.4 || bottom.a > 0.4 || left.a > 0.4 || right.a > 0.4 || topLeft.a > 0.4 || topRight.a > 0.4 || bottomLeft.a > 0.4 || bottomRight.a > 0.4 ) {
if (current.a != 0.0) {
current = mix(color , current , current.a);
} else {
current = color;
}
}
}
gl_FragColor = current;
}
ANSWER
Answered 2021-Nov-28 at 16:45In my filters, the smoothness is achieved by a simple boxblur on the border.. You have decided that alpha > 0.4 is a border. The value of alpha between 0-0.4 in surrounding pixels gives an edge. Just blur this edge with a 3x3 window to get the smooth edge.
if ( current.a != 1.0 ) {
// other processing
if (current.a > 0.4) {
if ( (top.a < 0.4 || bottom.a < 0.4 || left.a < 0.4 || right.a < 0.4
|| topLeft.a < 0.4 || topRight.a < 0.4 || bottomLeft.a < 0.4 || bottomRight.a < 0.4 )
{
// Implement 3x3 box blur here
}
}
}
You need to tweak which edge pixels you blur. The basic issue is that it drops from an opaque to a transparent pixel - what you need is a gradual transition.
Another options is quick anti-aliasing. From my comment below - Scale up 200% and then scale down 50% to original method. Use nearest neighbour scaling. This technique is used for smooth edges on text sometimes.
QUESTION
This is my JS page where I need to implement the GridList
component to show multiple tiles and is scrollable horizontally after list size crosses screen limits.
import React,{ useState} from "react";
import Header from "../../common/header/Header";
import "./Home.css";
import { GridList, GridListTile, GridListTileBar} from "@material-ui/core";
const images = [
{ thumbnail: { uri: 'https://lorempixel.com/200/200/animals',name:'animals'}},
{ thumbnail: { uri: 'https://lorempixel.com/200/200/city' ,name:'city'}},
{ thumbnail: { uri: 'https://lorempixel.com/200/200/city' ,name:'city'}},
{ thumbnail: { uri: 'https://lorempixel.com/200/200/city' ,name:'city'}},
{ thumbnail: { uri: 'https://lorempixel.com/200/200/nature' ,name:'nature'} },
{ thumbnail: { uri: 'https://lorempixel.com/200/200/cats' ,name:'cats'} },
{ thumbnail: { uri: 'https://lorempixel.com/200/200/cats' ,name:'cats'} },
{ thumbnail: { uri: 'https://lorempixel.com/200/200/cats' ,name:'cats'} },
];
export default function Home() {
return (
<>
Upcoming Movies
{images.map((image) => (
))}
);
}
ANSWER
Answered 2021-Oct-16 at 18:28Note: In the newer versions of MUI, GridList
's been changed to ImageList
, the code below uses the latest API.
You can fill the column instead of row by using the code below:
{images.map((image) => (
))}
gridAutoFlow: 'column'
: Tell the grid to create another column if there is no space left instead of going to the next row.gridTemplateColumns: 'repeat(auto-fill, minmax(160px, 1fr))'
: Set the column min and max width, min is160px
, if there is more than enough space (no need for horizontal scrollbar), set each column width equally.gridAutoColumns: 'minmax(160px, 1fr)'
: Same as above but for the columns outside of the viewport.
V5
V4
ReferencesQUESTION
I want to define equality for some type that can be part of other objects or collections using cats/kitten. I don't want to have to define the equality for every other class. For example:
import cats.Eq
case class Foo(a: Int, bar: Bar)
case class Bar(b: Int)
object BarEq {
implicit val barEq: Eq[Bar] = Eq.instance[Bar] {
(b1, b2) => b1.b +1 == b2.b
}
}
and then a test defined as
import cats.derived.auto.eq._
class BarEqTest extends FlatSpec with cats.tests.StrictCatsEquality {
import BarEq._
"bareq" should {
"work" in {
Foo(1, Bar(1)) should ===(Foo(1, Bar(2)))
Bar(1) should ===(Bar(2))
Some(Foo(1, Bar(1))) should ===(Some(Foo(1, Bar(2))))
}
}
}
this works fine, but if I try to add the following test case
Seq(Foo(1, Bar(1))) should ===(Seq(Foo(1, Bar(2))))
I get
[Error] types Seq[Foo] and Seq[Foo] do not adhere to the type constraint selected for the === and !== operators; the missing implicit parameter is of type org.scalactic.CanEqual[Seq[Foo],Seq[Foo]]
one error found
How come the auto derived eq works with Option
but not Seq
, and how can I make it work? I tried to add import cats.instances.seq._
but that did not work either.
ANSWER
Answered 2021-Oct-16 at 13:46Cats defines an instance of Eq
for scala.collection.immutable.Seq
, not for generic scala.collection.Seq
(or moreover scala.collection.mutable.Seq
)
import scala.collection.immutable.{BitSet, Queue, Seq, SortedMap, SortedSet}
private[kernel] trait EqInstances0 {
implicit def catsKernelEqForSeq[A: Eq]: Eq[Seq[A]] = cats.kernel.instances.seq.catsKernelStdEqForSeq[A]
}
https://github.com/typelevel/cats/blob/main/kernel/src/main/scala/cats/kernel/Eq.scala#L283-L285
Starting from Scala 2.13.0 scala.Seq
is scala.collection.immutable.Seq
. But in Scala 2.12.x scala.Seq
is scala.collection.Seq
.
https://github.com/scala/scala/releases/tag/v2.13.0
So in Scala 2.12 import correct collection type
import scala.collection.immutable.Seq
Seq(Foo(1, Bar(1))) === Seq(Foo(1, Bar(2))) // true
or define your own instance of Eq
for necessary collections
import cats.kernel.instances.StaticMethods
implicit def genericSeqEq[A: Eq]: Eq[collection.Seq[A]] = new Eq[collection.Seq[A]] {
override def eqv(xs: collection.Seq[A], ys: collection.Seq[A]): Boolean =
if (xs eq ys) true
else StaticMethods.iteratorEq(xs.iterator, ys.iterator)
}
Seq(Foo(1, Bar(1))) === Seq(Foo(1, Bar(2))) // true
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cats
You can build CATS from sources on you local box. You need Java 11+. Maven is already bundled.
When using the native binaries (not the uberjar) there might be issues when using dynamic values in the CATS files. This is due to the fact that GraalVM only bundles whatever can discover at compile time. The following classes are currently supported:.
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page